Menu closeOnSelect prop won't work with MenuOptionGroup
See original GitHub issue🐛 Bug report
While using a MenuOptionGroup
with type radio the closeOnSelect
property of the Menu
won’t work always. Sometimes it closes the menu, sometimes it won’t.
💥 Steps to reproduce
- Go to Chakra Menu page at the Menu Option Group section using this link
- Change the
closeOnSelect={false}
of theMenu
component tocloseOnSelect={true}
- Opens the rendered menu and try to select an option. You should try a few times. After a few attempts it would close, but not as expected (on the first attempt)
💻 Link to reproduction
https://chakra-ui.com/docs/overlay/menu#menu-option-groups
🧐 Expected behavior
After clicking on a given item, it should close the menu
🧭 Possible Solution
No idea =/
📝 Additional information
The closeOnSelect
works on MenuGroup
(but not MenuOptionGroup)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
react-select-with-absolute-menu - npm package - Snyk
You can provide a custom className prop to the <Select> component, which will be added to the base .Select className for the outer...
Read more >Close react-select menu programmatically - Stack Overflow
You can use the menuIsOpen prop and control the value of this prop with a button something like this: class App extends React....
Read more >Changelog - Chakra UI
Fix issue where menu items cannot type type=submit ... Fixed an issue where the prop isLazy did not work as expected. ... Won't...
Read more >Custom Select | laravel-form-components - Randall Wilk
This will output a custom select menu with options for foo and bar . The menu is toggled open and closed by using...
Read more >Design System built with React - Sajari UI
MenuDivider : A visual separator for menu items and groups. MenuOptionGroup : A wrapper for checkable menu items (radio and checkbox); MenuItemOption :...
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 FreeTop 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
Top GitHub Comments
Pushed a fix for this, thanks to your help @Sqvall 💖.
We’ll release an update shortly.
The problem in this place. https://github.com/chakra-ui/chakra-ui/blob/cbf8bbdf02eff45a57a28307ec9c3137ce845420/packages/menu/src/use-menu.ts#L337-L341 Menu item option - it button contains 2 span (icon and text). When we click on text or icon - isTargetMenuItem called with span or svg element in event.target ant event not propagation to the button. Because of this, the condition does not pass:
We cannot attach to the parent for this event targets because its broke for icon or if children include another DOM elements.
May be somebody can fix it? Or give me a hint what would be the best option to fix it correctly.