MenuOptionGroup onChange does not work on new menu items added dynamically
See original GitHub issue🐛 Bug report
Re-renders won’t update onChange
because of memoization here: https://github.com/chakra-ui/chakra-ui/blob/a505441cafa1f1a5593eeae395feadd8083aae14/packages/menu/src/use-menu.ts#L572 .
💥 Steps to reproduce
<MenuOptionGroup
type="radio"
onChange={(ids) => {
const selected = items.filter((deck) => ids.includes(deck.id))>
{items.map((item) => (
<MenuItemOption key={item.id} value={item.id}>
{item.name}
</MenuItemOption>
))}
- add a new item to
items
array dynamically by setting state in parent - click on item in menu
selected
isundefined
🧐 Expected behavior
New item should be selectable.
🧭 Possible Solution
Don’t useCallback
in https://github.com/chakra-ui/chakra-ui/blob/a505441cafa1f1a5593eeae395feadd8083aae14/packages/menu/src/use-menu.ts#L572 .
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Dynamically created select menu on change not working
I'm then trying to add an on 'change' event handler to this added select menu. The on 'change' event doesn't work on thw...
Read more >Menu - Chakra UI
MenuOptionGroup : A wrapper for checkable menu items (radio and checkbox). ... {/* MenuItems are not rendered unless Menu is open */}. <MenuItem>New...
Read more >ReactJS Evergreen Menu Component - GeeksforGeeks
onChange : It is a callback function that is called when selection changes. options: It is used to denote the list of options...
Read more >How to Change menu items dynamically in React ... - Syncfusion
The items visible in the ContextMenu can be changed dynamically based on the context you open. To achieve this behavior, initialize ContextMenu with...
Read more >How to make a dynamic onChange handler to <NumberInput ...
This behavior doesn't allow for an onChange handler that can be applied to ... value without having to create a new state or...
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
You can solve this by using the MenuItemOption, use the
onClick
props together with theisChecked
props and this should give you the same behavior you are looking for. I hope this helpsAny news on this one?