Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't click without scroll being changed #254

Closed
leads opened this issue Jul 11, 2023 · 3 comments
Closed

Can't click without scroll being changed #254

leads opened this issue Jul 11, 2023 · 3 comments

Comments

@leads
Copy link

leads commented Jul 11, 2023

Hi please see this codesandbox example and demo.

Here I am using a Modal we have built and it uses body-scroll-lock-upgrade and react-focus-lock.

If you open the Modal then scroll down the list, try clicking the label text. It will jump you back up. You can click the checkbox directly but then trying another click elsewhere it will scroll back to that focussed item.

I made a demo without checkboxes and the same thing happens if you click in a grey box. Also a demo without the body-scroll-lock.

Hopefully this is an implementation mistake on our behalf that we have missed. Any ideas?

Thanks

@denkristoffer
Copy link

Use preventScroll in focusOptions: https://codesandbox.io/s/happy-pascal-ndd77z?file=/src/Modal.tsx:3109-3168

See #162

@theKashey
Copy link
Owner

Root cause - you have a focusable element "above" focus lock. When you click on the "text" you are selecting this element and as it is "above" focus (or "outside") the focus will be returned to where it belongs.

The fix is simple - wrap dialog with focus-lock, not the other way around - https://codesandbox.io/s/busy-blackwell-6svn9r?file=/src/Modal.tsx

How to check: you should be able to select text with a mouse. If you cannot, then something is wrong. Focus-lock implicitly allows for focus to reside on body, but nowhere else.

@leads
Copy link
Author

leads commented Jul 14, 2023

Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants