DropdownMenu
Open a list of actions from a button.
Playground
Usage
The menu opens at the left edge of its trigger. Use the arrow keys to move between enabled items and Escape to return to the trigger. In the playground, press F on the trigger or inside the menu to toggle the map’s favorite status.
Hover over Add to collection or focus it and press Right Arrow to open its submenu. Choose a collection with Enter, or press Left Arrow to return to the parent item. Wrap SubTrigger and SubContent in DropdownMenu.Sub to create a submenu.
Use an icon snippet for a leading icon. The optional shortcut displays one key or an array of keys using Kbd. The app handles the keypress and can expose it to assistive technology with aria-keyshortcuts. Use href for navigation or disabled for an unavailable action.
<script lang="ts"> import StarIcon from 'phosphor-svelte/lib/StarIcon' import { Button } from '@allmaps/ui/button' import * as DropdownMenu from '@allmaps/ui/dropdown-menu'
let { toggleFavorite }: { toggleFavorite: () => void } = $props()</script>
<DropdownMenu.Root> <DropdownMenu.Trigger> {#snippet child({ props })} <Button {...props}>Map actions</Button> {/snippet} </DropdownMenu.Trigger> <DropdownMenu.Content> <DropdownMenu.Item onSelect={toggleFavorite} shortcut="F"> {#snippet icon()}<StarIcon />{/snippet} Toggle favorite </DropdownMenu.Item> <DropdownMenu.Item href="/components/kbd">View keycaps</DropdownMenu.Item> <DropdownMenu.Item disabled>Download map</DropdownMenu.Item> </DropdownMenu.Content></DropdownMenu.Root>