Repository navigation
fix(modal): only the topmost sheet modal redirects focus to its handle - #31805
Open
AdityaxDeore wants to merge 1 commit into
Open
AdityaxDeore wants to merge 1 commit into
AdityaxDeore wants to merge 1 commit into
Conversation
When two sheet modals are presented back to back, the focus trap moves focus between them; the covered sheet's onModalFocus also redirected focus to its own drag handle, the trap moved focus back again, and the two ping-ponged until the call stack overflowed. Guard the redirect with getPresentedOverlay(document, 'ion-modal') === el so only the topmost presented modal redirects focus to its handle. A covered sheet receiving focus directly leaves focus on its host, where the trap can move it to the top overlay without a second redirect. Regression test: core/src/components/modal/test/modal-sheet-focus.spec.tsx (2 tests: covered sheet does not redirect, topmost sheet still does). Fail-before: 1 failed / 1 passed; pass-after: 2/2. Neighbouring specs (modal-attributes, modal-id, overlay-focus-boundary): 3 suites, 15 tests, all passed. Core build, eslint and prettier clean. Fixes ionic-team#31757
|
@AdityaxDeore is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #31757
Problem
Two
ion-modalsheets presented back to back overflow the call stack. When the focus trap moves focus between the sheets, the covered sheet'sonModalFocus(added by #31293) also redirects focus to its own drag handle, the trap moves focus back again, and the two ping-pong until the stack overflows. It also reproduces on v8 when the sheets sethandleBehavior="cycle"explicitly.Fix
Guard the redirect in
onModalFocus(core/src/components/modal/modal.tsx) so only the topmost presented modal redirects focus to its handle:A covered sheet receiving focus directly now leaves focus on its host, where the trap can move it to the top overlay without a second redirect. No other behaviour changes: the guard only narrows when the existing redirect fires.
Testing
New regression test
core/src/components/modal/test/modal-sheet-focus.spec.tsx(Stencil spec test, two sheet modals withhandleBehavior="cycle"; theoverlay-hiddenclass is removed from both hosts to simulate presentation, which is what makesgetPresentedOverlay()count a modal as presented):focusfocusFail-before on the unfixed code: 1 failed / 1 passed (the covered-sheet test failed — the handle's
focuswas called). Pass-after: 2/2. Neighbouring specs (modal-attributes,modal-id,overlay-focus-boundary): 3 suites, 15 tests, all passed. Core build, eslint and prettier are clean.Disclosure: AI coding assistance was used in preparing this change.