[MenuItem] Menu closes when clicking on a MenuItemOption
See original GitHub issueWhen you have a MenuOptionGroup
of type=“radio” inside a Menu, clicking on any of this options will make the menu to close. I’d like to give my users some kind of “change” feedback, when selecting this options. Same as closeOnSelect
property of Menu
component, I’d like to have a closeOnSelect for MenuItem
and MenuItemOption
components, so I can choose which Items should close the menu on selection, and which items should keep the menu open.
Here’s a small sandbox showing this behavior with a “language selection” example: I’d like to keep the menu open when clicking on ‘Spanish’ or ‘English’, so the users have instant feedback on this change.
https://codesandbox.io/s/small-paper-exgwi?file=/src/App.tsx
I am aware of some workarounds to make this work, but it will be great if this was supported by Chakra with a property on the MenuItem components.
Thanks in advance! 😄
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top GitHub Comments
@with-heart if the solution proposed in my previous comment is acceptable, I can open a PR.
Edit: that being said, there could be a more declarative way of doing this (working with props rather than events), by allowing
MenuItem
andMenuItemOption
to pass acloseOnSelect
that overrides the parentMenu
’s value.Eg:
Implementation in
useMenuItem
(works by proxy forMenuItemOption
):That’s a great idea @franky47, thanks for sharing your thoughts.
I think it makes sense to be able to control
closeOnSelect
perMenuItem
. Feel free to create a PR for this.