-
Notifications
You must be signed in to change notification settings - Fork 13.3k
fix(modal): focus the dialog wrapper on present so screen readers can enter the modal #31260
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
base: main
Are you sure you want to change the base?
Changes from all commits
ce1dc72
deeca02
58782ef
5b25d95
7acf4eb
b98cbb3
cbca643
fe89761
ca26b3b
b1ca7aa
f6363c2
4d16cd7
f28d893
481e513
03397f2
870c497
0a1b6f3
2d3cb96
16d0939
b0b5256
5ddc39c
7449639
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,9 +113,18 @@ export const createSwipeToCloseGesture = ( | |
| return false; | ||
| }; | ||
|
|
||
| /** | ||
| * In Firefox, pressing over a text caret in the focusable wrapper can | ||
| * start a native drag that swallows the gesture's pointer events. | ||
| * Cancel native drag while the gesture is active. | ||
| */ | ||
| const preventNativeDragStart = (ev: DragEvent) => ev.preventDefault(); | ||
|
Comment on lines
+116
to
+121
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I test this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Manual repro (Firefox): present a sheet modal and drag the header immediately. Because the wrapper is now focusable and contains text, Firefox starts a native text drag that swallows the gesture's pointer events, so Automated: the existing 🤖 Addressed by Claude Code |
||
|
|
||
| const onStart = (detail: GestureDetail) => { | ||
| const { deltaY } = detail; | ||
|
|
||
| el.addEventListener('dragstart', preventNativeDragStart); | ||
|
|
||
| /** | ||
| * Get the initial scrollY value so | ||
| * that we can correctly reset the scrollY | ||
|
|
@@ -237,6 +246,8 @@ export const createSwipeToCloseGesture = ( | |
| }; | ||
|
|
||
| const onEnd = (detail: GestureDetail) => { | ||
| el.removeEventListener('dragstart', preventNativeDragStart); | ||
|
|
||
| const velocity = detail.velocityY; | ||
| const step = detail.deltaY / height; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,14 @@ ion-backdrop { | |
| z-index: 10; | ||
| } | ||
|
|
||
| /** | ||
| * The wrapper receives programmatic focus for screen readers but should not | ||
| * show a visible focus ring, which is meant only for keyboard navigation. | ||
| */ | ||
| .modal-wrapper { | ||
| outline: none; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is no longer required with my suggested change to query for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still required. Because |
||
| } | ||
|
gnbm marked this conversation as resolved.
|
||
|
|
||
| .modal-shadow { | ||
| position: absolute; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1644,10 +1644,16 @@ export class Modal implements ComponentInterface, OverlayInterface { | |||
| same element. They must also be set inside the | ||||
| shadow DOM otherwise ion-button will not be highlighted | ||||
| when using VoiceOver: https://bugs.webkit.org/show_bug.cgi?id=247134 | ||||
|
|
||||
| tabIndex={-1} is required so present() can move focus to this | ||||
| element (which carries the dialog role) instead of the role-less | ||||
| host. role="dialog" alone does not make an element focusable, so | ||||
| without the tabindex focus() would be a no-op. | ||||
| */ | ||||
| role="dialog" | ||||
| {...inheritedAttributes} | ||||
| aria-modal="true" | ||||
| tabIndex={-1} | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment on
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping |
||||
| class="modal-wrapper ion-overlay-wrapper" | ||||
| part="content" | ||||
| ref={(el) => (this.wrapperEl = el)} | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I test this?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manual repro (Firefox): present a sheet modal and drag the header immediately. Because the wrapper is now focusable and contains text, Firefox starts a native text drag that swallows the gesture's pointer events, so
ionDragStartnever fires and the sheet cannot be dragged. Cancellingdragstartwhile the gesture is active fixes it.Automated: the existing
should emit ionDragStart, ionDragMove, and ionDragEnd eventse2e is the fail/pass gate (I confirmed it fails 3/3 on Firefox with this removed), andshould cancel native drag and drop only while the gesture is activeassertsdragstartisdefaultPreventedduring the gesture and not after.