react-focus-lock
react-focus-lock copied to clipboard
Focus Lock navigation breaks with multiple tabIndex="-1" wrappers
trafficstars
Issue Description
When using react-focus-lock, the focus navigation within a dialog breaks when a focusable component that displays the dialog is wrapped in a component with tabIndex="-1", and the component following it is also wrapped in a component with tabIndex="-1".
The focus navigation is not calculated correctly and gets stuck in a loop, returning to the starting component instead of cycling through all focusable elements.
Steps to Reproduce
- Open the CodeSandbox demo
- Click the "Open modal 1" button to open the dialog
- Press "Tab" twice or more
- Observe that the focus does not move and is stuck in a loop
Expected Behavior
Focus should move in a cycle through all focusable components within the dialog.
Environment
- react-focus-lock version: 2.13.5
- React version: (as specified in the CodeSandbox)
Location of the error
https://github.com/theKashey/focus-lock/blob/ab0a54559ab3db3ce53fbe82fe73abe3475027d1/src/solver.ts#L98