question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Go to Chakra Menu page at the Menu Option Group section using this link
  2. Change the closeOnSelect={false} of the Menu component to closeOnSelect={true}
  3. 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
segunadebayocommented, Jun 7, 2021

Pushed a fix for this, thanks to your help @Sqvall 💖.

We’ll release an update shortly.

3reactions
Sqvallcommented, Jun 5, 2021

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). Screenshot from 2021-06-05 22-21-16 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:

!!target.getAttribute("role")?.startsWith("menuitem")

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found