Focus trap doesn't work in React 18
See original GitHub issueI’m using focus-trap-react 9.0.1
and the focus trap doesn’t seem to work.
If I focus on the first <input>
and press Tab
twice, I land on the second <input>
that sits outside the trap.
What am I missing?
<div className="App">
<FocusTrap>
<div>
<input type="text" />
<button>Submit</button>
</div>
</FocusTrap>
<input type="text" placeholder="I am outside the trap" />
</div>
Issue Analytics
- State:
- Created a year ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
focus-trap-react - npm
A React component that traps focus.. Latest version: 10.0.2, last published: a month ago. Start using focus-trap-react in your project by ...
Read more >focus-trap-react demo
This focus trap will fade in when activated and fade out when deactivated. It logs a message to the console when the trap...
Read more >React Focus Trap component - MUI Base
The Focus Trap component prevents the user's focus from escaping its children components.
Read more >Accessibility in React | How To Trap Focus Inside a Modal
Trapping focus is one of the important issues concerning accessibility.
Read more >Top 5 focus-trap-react Code Examples - Snyk
querySelector() to find the DOM node), or a function that returns a DOM node. escapeDeactivates {boolean}: Default: true. If false, the Escape key...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For the record, I am not a fan of this strict mode. For one thing, it violates correct assumptions about componentWillUnmount
(emphasis mine)
Strict mode violates this assumption. I get that React is looking forward to this day where they will decide which parts of the tree to unmount when the user goes away somewhere, but strict mode violates normal assumptions, and then they expect the entire community to not operate under those assumptions??
My pleasure!