-
-
Notifications
You must be signed in to change notification settings - Fork 173
fix(BModal): prevent focus trap error when no tabbable elements exist #2864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(BModal): prevent focus trap error when no tabbable elements exist #2864
Conversation
|
|
Co-authored-by: VividLemon <31498096+VividLemon@users.noreply.github.com>
|
This PR is stale because it has been open for 45 days with no activity. It will not be auto-closed |
packages/bootstrap-vue-next/src/composables/useActivatedFocusTrap.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: VividLemon <31498096+VividLemon@users.noreply.github.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
commit: |
* upstream/main: (28 commits) fix(BToggle)! Remove redundant attribute cleanup & update docs for accessibility attributes on show/hide components (bootstrap-vue-next#2918) chore: release main (bootstrap-vue-next#2912) fix: allow custom component props in orchestrator create methods with type safety (bootstrap-vue-next#2922) fix(BModal): prevent focus trap error when no tabbable elements exist (bootstrap-vue-next#2864) Update package description for clarity (bootstrap-vue-next#2917) Update project description for clarity and detail test: add event emission tests for BTable and BTableLite (bootstrap-vue-next#2915) fix(BTableLite): Use primary key to persist row-details state when items change (bootstrap-vue-next#2871) chore: release main (bootstrap-vue-next#2896) feat(BTable): add configurable debouncing ci: Add publint to the build process (bootstrap-vue-next#2909) docs(Offcanvas): Parity pass (bootstrap-vue-next#2900) fix(directives): Robustness fixes for directives (bootstrap-vue-next#2906) docs(BFormInput): document @wheel.prevent for disabling mousewheel events (bootstrap-vue-next#2903) fix(typings): Fix paths to `*.d.mts` files (bootstrap-vue-next#2907) feat: add name and form props to BFormRating for form submission (bootstrap-vue-next#2895) docs: refactor docs to avoid duplication and boilerplate code (bootstrap-vue-next#2891) docs(BToast): Parity (bootstrap-vue-next#2887) docs(BModal): fix attribute to hide footer (bootstrap-vue-next#2888) docs(BPlaceholder): Parity pass (bootstrap-vue-next#2886) ...
Problem
When using multiple BModal components in a stacked configuration, a console error would occur under specific conditions:
This would result in the error:
The error occurred because when the second modal closed, the focus trap tried to return focus to the first modal, but it had no tabbable elements available.
Root Cause
In
useActivatedFocusTrap.ts, thefallbackFocusoption was being set to a static value at initialization time:Since
fallbackFocus.ref.valuewasnullduring initialization, the focus trap had no valid fallback element when attempting to deactivate.Solution
Changed
fallbackFocusfrom a static value to a dynamic function that resolves at runtime:This ensures that when the focus trap deactivates, it can always find a valid fallback element:
fallbackFocus.ref.value)document.body'body'The SSR check ensures the code works correctly in server-side rendering environments where
documentis undefined.Testing
Screenshots
Before fix - Error scenario:

After fix - No errors:

The fix is minimal and surgical, addressing only the specific edge case without affecting any existing functionality.
Fixes #2862
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.