sterling-svelte  2.0.23
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.
anchorOriginPopover2Nonant | undefinedno'bottom-left'The point in a 3x3 grid on the anchor that should be used as the origin for the menu.
itemsSnippet | undefinednoundefinedThe items to display in the menu.
lightDismissboolean | null | undefinednotrueWhen true, the menu closes when another element is clicked or focused. Also closes when another dropdown opens.
menuClassstringno''Additional class names to apply to the menu.
offsetXnumberno0The how many pixels to move the menu left (negative) or right (positive).
offsetYnumberno0The how many pixels to move the menu up (negative) or down (positive).
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.
placement'auto'| Popover2Nonant | undefinedno'bottom-right'How the menu should be positioned relative to the anchor point. When 'auto', placement follows anchorOrigin.
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>