-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Handle edge cases in with-constrained-tabbing. #10174
Conversation
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.
This component could use some tests.
* When pressing Tab and none of the tabbables has focus, the keydown | ||
* event happens on the wrapper div: move focus on the first tabbable. | ||
*/ | ||
} else if ( ! tabbables.includes( event.target ) ) { |
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.
Would it be enough to test event.target === this.focusContainRef.current
? More optimized, more explicit to what we are testing.
Or are there other cases where the target of the tab press would itself not be tabbable? I guess might account for elements with tabIndex=-1 within the content? If so, should be update the comment to reflect this?
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.
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.
Ah! This is fine then.
Checks edge cases in withConstrainedTabbing.
42b8656
to
2ee25cc
Compare
Added tests co-authored with @talldan. Should be ready to merge. |
Description
Handle edge cases to keep tabbing constrained in
withConstrainedTabbing
, for example when clicking in the content and then pressing Tab. See conversation on #9973To test:
Previously, focus went to the document root.
By adding
tabIndex="-1"
to thewithConstrainedTabbing
it is possible to detect when theevent.target
is not the firstTabbable orlastTabbable
. This happens, for example when the content is clicked and then Tab is pressed again. In this edge case, focus is moved to the first tabbable.Fixes #10165