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

[Dialog - FocusScope] Focus is not trapped inside the dialog opened #3116

Open
Klynger opened this issue Sep 11, 2024 · 0 comments
Open

[Dialog - FocusScope] Focus is not trapped inside the dialog opened #3116

Klynger opened this issue Sep 11, 2024 · 0 comments

Comments

@Klynger
Copy link

Klynger commented Sep 11, 2024

Bug report

Current Behavior

In certain conditions, if you have a dialog, you can still navigate through elements outside the dialog using the tab key right after you open it.

CleanShot.2024-09-11.at.15.02.01.mp4

Expected behavior

The dialog should trap the focus when opened and not let it leave until it’s closed.

Reproducible example

CodeSandbox Template

  1. Click on "Delete account"
  2. Hold Shift and press Tab
  3. You will start navigating on elements behind the dialog and across the codesandbox window

Suggested solution

I'm not familiar with the code, but I imagine FocusScope is responsible for trapping the focus inside when mounted. However, there might be some use cases where you folks intended to use FocusScope without trapping the focus on mount. If that’s the case, I think Dialog/AlertDialog should pass a prop to FocusScope to ensure it traps the focus on mount.

https://github.com/radix-ui/primitives/tree/main/packages/react/focus-scope

Additional context

Your environment

Software Name(s) Version
Radix Package(s) FocusScope latest
React n/a
Browser Chrome 128.0.6613.120 (Official Build) (arm64)
Assistive tech
Node n/a
npm/yarn n/a
Operating System n/a
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

1 participant