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.

Doesn't seem to work in other documents

See original GitHub issue

I appreciate the effort you have put into making the focus trap library work in iframes and child windows, but unfortunately it seems like maybe the React version is not prepared for this?

I’m using the FocusTrap like <FocusTrap active={element !== null} focusTrapOptions={{document}}>, where document is the document of the child window (derived from element.ownerDocument), but the focus trap still isn’t trapping focus. When the same component is used in the main document, it works just fine.

Do you know what could be the cause of the issue?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:25 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
stefcameroncommented, Dec 4, 2021

And there’s no way you can change your code to delay the inclusion of the focus trap component to when the document has stabilized? Like don’t render the trap until you have the document you need…

This… is impossible? Like, my component doesn’t know where it’s mounted until it’s been mounted.

That’s true. Then rendering with <FocusTrap> could cause the div to change, causing the ref to change, and I guess it could be a different document at that point, though that seems unlikely. Still, it wouldn’t be totally “clean” to assume it’s the same document.

Because this is kind of a big change to the way it’s currently working.

It’s not. It’s highly unlikely people are relying on when the document field is read from the options. If anything this fixes a bug, where the focus trap reads the options before they are ready.

I’ll give this some thought. It’s a significant change in terms of when the trap gets created. I’ll have to check focus-trap to see if creating the trap triggers any events for which you might expect a callback in one of the options, in which case, you wouldn’t get the callback at the same time anymore.

If that turns out to be a problem, then another option might be to promote the document option to a prop (instead of nesting it in focusTrapOptions where there’s no “notification” if it changes) and then re-create the trap if that prop changes. Then we could maintain existing behavior and only have changes affect changing the document.

1reaction
stefcameroncommented, Dec 4, 2021

So something like componentDidMount(), only call this.setupFocusTrap() if this.props.active is true, and then in componentDidUpdate(), check if (!prevProps.active && this.props.active) and call this.setupFocusTrap() (if it doesn’t already exist).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft Word Not Responding? 8 Ways To Fix It
One way to fix this is to repair those corrupt documents and then open them with Word. Open Word on your computer. Use...
Read more >
How to troubleshoot problems that occur when you start or ...
Provides a guide to identify and resolve problems that you experience when you start Word.
Read more >
8 Ways to Fix the Grammarly Add-In Not Working in ...
Grammarly is great at detecting errors in your English, but sometimes it needs a little help with the Microsoft Word add-in on Windows....
Read more >
Can't Save Edited Document - Word Ribbon Tips
Load the original file (not the copy you used Open and Repair with) and use Save As to save the document in different...
Read more >
Microsoft Word Spell Check Not Working? (5 Solutions)
1. Click the File tab. 2. From the left menu, select Options at the bottom. 3. In the Word Options dialog, click Proofing....
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