platform icon indicating copy to clipboard operation
platform copied to clipboard

Allow adding custom properties to menu bar item and context menu item types

Open sissbruecker opened this issue 9 months ago • 1 comments

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>

sissbruecker avatar Feb 26 '25 12:02 sissbruecker