Allow setting constrained tabbing behaviour in useDialog hook #57877
Labels
[Feature] UI Components
Impacts or related to the UI component system
[Focus] Accessibility (a11y)
Changes that impact accessibility and need corresponding review (e.g. markup changes).
[Status] In Progress
Tracking issues with work in progress
[Type] Enhancement
A suggestion for improvement.
the
useDialog
hook currently does not provide developer control over whether the dialog has constrained tabbing or not.Instead this behaviour is conditionally set based on the
focusOnMount
prop. I spoke a bit with @andrewhayward about this away from Github and he suggested the following:@joedolson @jeryj Testing the a11y I noticed that there appears to be a focus trap which is active on the initial creation of the link only.
When you first create the link your focus is trapped within the preview or the editor form and it is not possible to TAB out. Only ESC allows you to escape focus trap.
If you then re-activate the link the focus trap is no longer in evidence.
Here's a video demonstrating what I mean:
Screen.Capture.on.2024-01-12.at.10-06-19.mp4
I'm going to try and look into this but if you have any ideas what could be causing this it would be greatly appreciated.
Update: I suspect this line is the source of the bug:
gutenberg/packages/compose/src/hooks/use-dialog/index.ts
Line 86 in 7fce392
In
inline.js
we set conditionally setfocusOnMount
. This is toPopover
auto-focusing when you place your cursor into an existing link format. This is so you can use arrow keys to move into the link format without having focus "stolen" by the Link UI popover.However, by doing this we toggle the constrained tabbing behaviour in the
useDialog
hook. This is why we get different behaviour.We'll need to work on this. For example, is it suitable to allow
Popover
to control whether it has a focus trap or not? That would also require modifyinguseDialog
to allow for this override.Originally posted by @getdave in #57726 (comment)
The text was updated successfully, but these errors were encountered: