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

MenuButton2

A button that opens and closes a menu.

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

<MenuButton2>
  <!-- button content -->
  {#snippet items()}
    <!-- <MenuItem> ... -->
  {/snippet}
</MenuButton2>

Members

Property NameTypeBindableDefaultComment
allowFlipPopover2FlipAxis | undefinednoundefinedWhich axis/axes allow the menu to flip to the other side when there is not enough space.
itemsSnippet | undefinednoundefinedThe items to display in the menu.
menuClassstringno''Additional class names to apply to the menu.
menuAnchorOriginPopover2Nonant | undefinedno'bottom-left'The point in a 3x3 grid on the button that should be used as the origin.
menuPlacement'auto'| Popover2Nonant | undefinedno'bottom-right'How the menu should be positioned relative to the anchor point. When 'auto', placement follows anchorOrigin.
openbooleanyesfalseWhen true, the menu is open.
onClose(value: string) => voidnoCalled when the menu or a descendant menu is closed.
onOpen(value: string) => voidnoCalled when the menu or a descendant menu is opened.
onSelect(value: string) => voidnoCalled when a descendant menu item is selected.
valuestringnoundefinedThe value uniquely identifying this menu button as the root of the menu hierarchy.

Considerations

  • MenuButton2 uses Popover2
  • Includes Button props, events, and methods.
  • Includes HTMLButtonElement props, events, and methods.

Anatomy

<Button class="sterling-menu-button-2">
  {@render children()}
</Button>

<Popover>
  <Menu class={menuClass}>
    {@render items()}
  </Menu>
</Popover>