platform
platform copied to clipboard
Allow adding custom properties to menu bar item and context menu item types
Description
Make it easy for developers to extend the MenuBarItem and ContextMenuItem types so that they can add additional properties to those. When handling item selection, developers should be able to retrieve those properties from the selected item in the event data without having to cast to a custom type.
Example
Adding an action function to menu items that can be called when an item is selected:
const items: ContextMenuItem<{ action: () => void }>[] = [
{
text: 'Copy',
action: () => copyToClipboard();
}
];
<ContextMenu
items={items}
onItemSelected={(e) => {
// Item type is inferred from items, so action can be used without casting
e.detail.value.action();
}}
>
...
</ContextMenu>