sterling-svelte  2.0.19
A modern, accessible, lightweight UI component library for Svelte.

MenuItem2

An item within a menu.

Code
<script lang="ts">
  import { MenuItem } from '@geoffcox/sterling-svelte';
</script>

<MenuItem text="sterling-svelte" value="menu-item-1">
  <!-- <MenuItem> ... -->
</MenuItem>

Members

Property NameTypeBindableDefaultComment
checkedboolean | null | undefinednofalseWhen true, the menu item is checked. Displayed only when role is set to menuitemcheckbox or menuitemradio.
itemSnippet | undefinednoundefinedWhen undefined, a default item is rendered with a chevron, checkmark, text, and shortcut.
menuClassstring | undefinednoundefinedA class applied to any child menu.
onClose(value: string) => voidnoundefinedCalled when the menu item is closed.
onOpen(value: string) => voidnoundefinedCalled when the menu item is opened.
onSelect(value: string) => voidnoundefinedCalled when the menu item is selected.
roleMenuItemRole | undefinedno'menuitem'The role of the menu item. Allows regular, checkbox, or radio menu items.
shortcutstring | undefinednoundefinedThe shortcut key sequence associated with the menu item. Not used if item is set.
textstring | undefinednoundefinedThe text of the menu item. Not used if item is set.
valuestringnoUniquely identifies the menu item within the menu hierarchy.

Types

Type NameDefinitionComment
MenuItemRole'menuitem' | 'menuitemcheckbox' | 'menuitemradio'

Considerations

  • MenuItem2 uses Popover2
  • Includes HTMLButtonElement props, events, and methods.

Anatomy

<button class="sterling-menu-item">
  <div class="item">
    {#if item}
      {@render item()}
    {:else}
      <div class="sterling-menu-item-display">
        <div class="check"></div>
        <div class="content"></div>
        <div class="shortcut"></div>
        <div class="chevron"></div>
      </div>
    {/if}
  </div>
  <Popover2>
    <Menu>
      {@render menu()}
    </Menu>
  </Popover2>
</button>