Dialog throws error if there are no focusable elements
See original GitHub issueI get the following error if I create a Dialog with no interactive components (just text):
Error: There are no focusable elements inside the <FocusTrap />
Issue Analytics
- State:
- Created 3 years ago
- Reactions:36
- Comments:26
Top Results From Across the Web
there are no focusable elements inside the <FocusTrap />
This error was being thrown when I tried to use the Simpler Alert Modal of TailwindUI. ... your Dialog needs a focusable element...
Read more >Getting a "There are no focusable elements inside the ...
I am trying to run this code but getting this error, I want to create a button that opens a headless UI. I...
Read more >ERROR Error: You can't have a focus-trap without at least one ...
If you are opening a dialog, please make sure the dialog does not render no content and there is no element to focus....
Read more >Dialog Components: Go Native HTML or Roll Your Own?
There's a new native HTML dialog element making the rounds and I ... And even if it's not my everyday primary focus, I...
Read more >How to Make Dialogs (The Java™ Tutorials > Creating a GUI ...
Most Dialogs present an error message or warning to a user, but Dialogs can ... When a modal Dialog is visible, it blocks...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found a way around that.
simply add a ref to the dialog and to a div inside the body UPDATE: found this mentioned in the docs https://headlessui.dev/react/dialog#managing-focus-within-your-dialog
You have to set
initialFocus
and also use it in your return code.Based on the example code @ https://headlessui.dev/react/dialog#rendering-to-a-portal they forgot to place
ref={cancelButtonRef}
inside an element (doesn’t have to be a button, could be a div or so too).