question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Focus trap doesn't work in React 18

See original GitHub issue

I’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>

Codesandbox

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
stefcameroncommented, Jun 18, 2022

For the record, I am not a fan of this strict mode. For one thing, it violates correct assumptions about componentWillUnmount

Once a component instance is unmounted, it will never be mounted again.

(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??

0reactions
stefcameroncommented, Jun 19, 2022

My pleasure!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found