[focus trap] Fix incorrect tab order when tabIndex >= 1 by mj12albert · Pull Request #48546 · mui/material-ui (original) (raw)

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