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.

Dialog's focus lock steals focus across frame boundaries

See original GitHub issue

🐛 Bug report

Current Behavior

Check the CodeSandbox example linked below. When opening the Dialog by clicking Show Dialog the button in it gets focussed (so far so good). Now use the mouse to return focus to the CodeSandbox and try to type something. As soon as you begin, the focus is returned to the button in the dialog.

The problem in our setup is a bit more complex as we’re opening a Google Driver Picker from a dialog but the underlying problem seems to be the same: The focus lock on the dialog is too aggressive.

Expected Behavior

The focus lock does not interfere with frame boundaries (ie. doesn’t steal focus from iframes or the like).

Reproducible example

CodeSandbox

Suggested solution(s)

At first I wanted to propose to make this configurable through a prop like disableFocusLock. However, given the extreme example of the CodeSandbox being rendered unusable maybe there is a more holistic solution to this. Maybe this is even an issue in react-focus-lock?

Happy to help implement something after a pointer in the right direction 🙌

Your environment

Software Name(s) Version
Reach Package @reach/dialog latest (0.10.0)
React 16.12.0
Browser Chrome

Edit: This might be related to #83

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
chaancecommented, Apr 22, 2020

Added the unstable_lockFocusAcrossFrames prop in 0.10.1

3reactions
theKasheycommented, Apr 17, 2020

I am adding new crossFrame option, right now defaults to true, as long as this behaviour might introduce a breaking change for someone.

  • setting crossFrame=true will work “as today”. Focus will try to keep focus
  • setting crossFrame=false will work “as proposed”. Iframes would be treated as “pages”, and let you move focus outside.

I am not sure which behaviour is actually correct - iframes are usually a part of a page, a part of your product, and the only exemptions are non-production examples like code-sandbox.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent the window from stealing focus. - Microsoft Q&A
I create a dialog box without a frame, assign the WS_EX_LAYERED style, and move it over the main window within certain boundaries, and...
Read more >
How to keep focus within modal dialog? - Stack Overflow
I have found some working examples, like the following: JQuery dialog: https://jqueryui.com/dialog/#modal-confirmation. dialog HTML 5.1 element ...
Read more >
Why are dialogs still a thing? - Why is stealing focus stil...
If you cannot make a thing without a dialog, focus lock, or focus theft then maybe the thing you were trying to make...
Read more >
LabVIEW - Stealing focus - NI Community
Solved: Hello. I need to create a pop-up action in my VI, and make it show up above all other applications - steal...
Read more >
Fixed issues in InDesign - Adobe Support
Enabling Preview of a document causes Create New Document dialog to lose focus. Trouble in typing comments in Korean when the Review panel...
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