Skip to content

Focus Lock navigation breaks with multiple tabIndex="-1" wrappers #371

@siarhei-epam

Description

@siarhei-epam

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

  1. Open the CodeSandbox demo
  2. Click the "Open modal 1" button to open the dialog
  3. Press "Tab" twice or more
  4. 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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions