onItemClick not propagated to sub menus
Environment Information
- Package version(s): 6.165.1
- Browser and OS versions: Chrome 73.0.3683.103, Mac OSX 10.14.4
Please provide a reproduction of the bug in a codepen:
https://codepen.io/anon/pen/vMvWjb?editors=1011
Actual behavior:
onItemClick must be defined in the subMenuProps for sub menus. I want to be able to re-use my onItemClick function for any item that is clicked anywhere in the menu.
Expected behavior:
If I pass onItemClick in menuProps, it will be invoked when clicking any item (unless overridden).
Priorities and help requested:
Are you willing to submit a PR to fix? Yes
Requested priority: Normal
Products/sites affected: BotFramework
Hi @a-b-r-o-w-n, from what I'm understanding you want onItemClick to be called on the first level of menu items even if subMenuProps have been specified. Did I understand correctly?
If that's so, I don't think we want to support this behavior. @micahgodbolt thoughts on this?
@khmakoto that's not what I'm suggesting. I would want the subMenuProps to override, but I think the onItemClick defined at the parent menu should propagate in the case that nothing has been defined at the subMenu or item level.
const menuProps = {
onItemClick: () => {}, // gets invoked when no other click handler present
items: [{
text: 'submenu without onItemClick',
subMenuProps: {
items: [{
text: 'foo' // should use menuProps.onItemClick
}, {
text: 'bar',
onClick: () => {} // this should overide menuProps.onItemClick
}]
}
}, {
text: 'submenu with onItemClick',
subMenuProps: {
onItemClick: () => {}, // should be the default handler for all items in subMenu
items: [{
text: 'foo' // should use subMenuProps.onItemClick
}, {
text: 'bar',
onClick: () => {} // this should overide menuProps.onItemClick
}]
}
}]
}
Hope that's helpful.
Really, in my case though, I just want to define the top-level onItemClick and have any click on a submenu item invoke it. However, I think this method of inheritance makes sense.
I think this would regress current behavior if done on current component. Could this be a variation? or even a wrapper around the current component. I defer to @micahgodbolt to provide feedback on this.
There are some worries I have with that approach.
What happens to clicks in the parent menu items when you have submenus? Do we allow the function call or do we stop it? If you have multiple nested submenus, how many levels deep does the function propagate?
Having a clear answer to these questions would help drive a decision on this.
Can you clarify your first question? I believe that a menu item that has a submenu has special click behavior, so it already ignores the onClick defined on that item.
I think it's fair to keep propagating the onItemClick down. In these scenarios, the user would most likely have a common click handler for all items in a sub menu.
I just ran into this problem as well. It's intuitive to think it propagates through, so, surprising to find out it doesn't.
I confirm this is an issue for me too. I require the label of a dropdown button to change accordingly to the text of the IContextualItem selected in the menu or in one of the submenus, but the OnItemClick triggers only in the first case.
Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.
Still require assistance? Please, create a new issue with up-to date details.