[Tabs] Fix Tabs focus state issue on close #3994
Merged
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.
WHY are these changes introduced?
Fixes #3993
(also fixes shopify/web issue #37890)
When the
Popover
component is handling the close event, it checks for the next focuseable element and focuses that, and otherwise focuses the popover trigger. However, the "next focuseable element" is determined by the nextFocuseableNode utility, which just checks based on element type and doesn't taketabindex
values into consideration.This breaks when used by the
Tabs
component, becauseTabs
has a set of buttons withtabindex="-1"
that are used to determine appropriate widths when resizing (theTabMeasurer
component). Because of this,nextFocuseableNode
is determined to be the first of theseTabMeasurer
buttons, but since it hastabindex="-1"
the focus is shifted to thewindow
.👀 Before 👀
bad.focus.state.mp4
WHAT is this pull request doing?
This PR moves the
TabMeasurer
's hidden tabs before the visible tabs. **Probably the better fix would be to update the focus utility to exclude buttons with negativetabindex
values, but given that this is a core utility that could have unintended knock-on effects. Hoping one of the PR reviewers has more insight into this 🙏 **👀 After 👀
focus.self.mp4
has.additional.focus.mp4
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist
README.md
with documentation changes