Implement Menu component
2b1cc3d13575cc5b2636293116ff758510d9adf2
How to find out which menu item has been clicked on? Method which is responsible for closing the popup doesn't pass any parameters
In my own implementation I've attached an event listener MDCSimpleMenu:selected like that:
var menuElement = document.querySelector('.mdc-menu-anchor > .mdc-simple-menu[for]');
var menu = new mdc.menu.MDCSimpleMenu(menuElement);
menu.listen('MDCSimpleMenu:selected', function (customEvent) {
var item = customEvent.detail.item
})
Hi @piotr-cz,
You can extend <MenuItem/> a little
<MenuItem onClick={() =>{console.log('item 1 clicked')}}>
Item 1
</MenuItem>
If this solution works for you, i'll update docs
Yes, but then I have to attach listener to each item separately, adding an argument with a hint which item has been clicked on
<MenuItem onClick={ () => { this.handleMenuItemClick(1) }}>
Item 1
</MenuItem>
It's not that bad at the end, but I was hoping that it's possible to attach the listener to the <Menu /> element like so:
<Menu onSelected={ this.handleMenuitemClick }>
{ this.props.menuItems.map(menuItem =>
<MenuItem key={ menuItem.id }>
{ menuItem.name }
</MenuItem>
)}
</Menu>
Make a sense. I'll extend it. Thanks
Do you try to use foundation & adapter components from material-components-web, for example: https://github.com/material-components/material-components-web/tree/master/packages/mdc-menu? Will it simplify and speedup component development in your point of view?
Hi @dogada , Sure it's easier and faster to develop, but the components will have more complicated states and it will influence the performance. See also #9 there is the same question
Hello @kradio3
Did you update the documentation ? because I don't know which solution you recommend ?