(React) Menu steals focus from modal on Menu.Item click
See original GitHub issueHi there,
First of all, thanks so much for tailwind and tailwindui!
The issue I’m facing relates to the latest release of @headlessui/react
.
I have a Menu component with a Menu Item that opens a modal (react-modal). The modal contains a form with an autofocus input that should grab and maintain focus on modal open. The problem is that the Menu Button steals focus away from the modal (so - focus is on the Menu Button behind the modal overlay) after Menu.Item click.
As a temporary-but-not-great workaround, I found that using setTimeout to slightly delay opening the modal after Menu.Item click usually results in the modal form getting and keeping focus.
I think this might be related to #47? Is there a proper way to prevent the Menu Button focus?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Same problem here and using refs didn’t fix it. Currently as a quick fix I use a timeout of 50ms to open a modal. In that case react-modal’s focus management works fine. https://github.com/getAlby/lightning-browser-extension/pull/709
Posting here for future reference, this was fixed in https://github.com/tailwindlabs/headlessui/pull/1782