Skip to content

[focus trap] Fix incorrect tab order when tabIndex >= 1#48546

Open
mj12albert wants to merge 2 commits into
mui:masterfrom
mj12albert:fix-focus-trap-positive-tabIndex
Open

[focus trap] Fix incorrect tab order when tabIndex >= 1#48546
mj12albert wants to merge 2 commits into
mui:masterfrom
mj12albert:fix-focus-trap-positive-tabIndex

Conversation

@mj12albert
Copy link
Copy Markdown
Member

@mj12albert mj12albert commented May 19, 2026

Preview: https://stackblitz.com/edit/yzacyhka-pvrbxm7l?file=package.json

The issue was that the keydown handler only special-cased Shift+Tab from the trap root and otherwise let the browser choose the next focus target.

When elements with tabIndex >= 1 exist, the browser’s next target after the positive sequence can be a tabIndex 0 element outside the trap instead of the next in-trap element.

The fix intercepts these and moves focus through the trap’s getTabbable() order.

Fixes #36479

@mj12albert mj12albert added type: bug It doesn't behave as expected. scope: focus trap Changes related to the focus trap. labels May 19, 2026
@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 19, 2026

Deploy preview

https://deploy-preview-48546--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+280B(+0.05%) 🔺+139B(+0.09%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@mj12albert mj12albert marked this pull request as ready for review May 19, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: focus trap Changes related to the focus trap. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FocusTrap] Wrong tab order when tabIndex >= 1

1 participant