Menu
A dropdown menu component for displaying a list of actions or options triggered by a button.
Anatomy
<script>
import {
Menu,
MenuButton,
MenuContent,
MenuItem,
MenuItemGroup,
MenuSeparator,
} from "@saas-ui/svelte/components/menu";
</script>
<Menu.Root>
<MenuButton>Open Menu</MenuButton>
<MenuContent>
<MenuItemGroup>
<MenuItem value="edit">Edit</MenuItem>
<MenuItem value="duplicate">Duplicate</MenuItem>
</MenuItemGroup>
<MenuSeparator />
<MenuItem value="delete">Delete</MenuItem>
</MenuContent>
</Menu.Root>Examples
Basic Accessibility
<Box>
<Menu.Root>
<Menu.Button>Open</Menu.Button>
<Menu.Content>
<Menu.Item value="new-txt">New Text File</Menu.Item>
<Menu.Item value="new-file">New File...</Menu.Item>
<Menu.Item value="new-win">New Window</Menu.Item>
<Menu.Item value="open-file">Open File...</Menu.Item>
<Menu.Item value="export">Export</Menu.Item>
</Menu.Content>
</Menu.Root>
</Box> Checkbox Accessibility
Menu.CheckboxItem.
<Box>
<Menu.Root closeOnSelect={false}>
<Menu.Button>
<Icon as={Funnel} size="sm" /> Status
</Menu.Button>
<Menu.Content>
<Menu.CheckboxItem checked={false} value="open"
>Open</Menu.CheckboxItem>
<Menu.CheckboxItem checked={true} value="closed"
>Closed</Menu.CheckboxItem>
</Menu.Content>
</Menu.Root>
</Box> Colours Accessibility
colour prop to change the colour scheme of the menu.
<HStack align="start" gap={4} class="flex-wrap">
{#each colours as colour}
<VStack gap={2} class="items-center">
<Text size="xs">{colour}</Text>
<Menu.Root {colour}>
<Menu.Button>Open</Menu.Button>
<Menu.Content>
<Menu.Item value="item-1">Item 1</Menu.Item>
<Menu.Item value="item-2">Item 2</Menu.Item>
<Menu.Item value="item-3">Item 3</Menu.Item>
</Menu.Content>
</Menu.Root>
</VStack>
{/each}
</HStack> Command Accessibility
Menu.ItemCommand component to display keyboard shortcuts alongside menu items.
<Box>
<Menu.Root>
<Menu.Button>Open</Menu.Button>
<Menu.Content>
<Menu.Item value="new-txt">
New Text File <Menu.ItemCommand>⌘E</Menu.ItemCommand>
</Menu.Item>
<Menu.Item value="new-file">
New File... <Menu.ItemCommand>⌘N</Menu.ItemCommand>
</Menu.Item>
<Menu.Item value="new-win">
New Window <Menu.ItemCommand>⌘⇧N</Menu.ItemCommand>
</Menu.Item>
<Menu.Item value="open-file">
Open File... <Menu.ItemCommand>⌘O</Menu.ItemCommand>
</Menu.Item>
<Menu.Item value="export">
Export <Menu.ItemCommand>⌘S</Menu.ItemCommand>
</Menu.Item>
</Menu.Content>
</Menu.Root>
</Box> Group Accessibility
Menu.ItemGroup to group related menu items together with an optional label.
<Box>
<Menu.Root>
<Menu.Button>Edit</Menu.Button>
<Menu.Content>
<Menu.ItemGroup title="Styles">
<Menu.Item value="bold">Bold</Menu.Item>
<Menu.Item value="underline">Underline</Menu.Item>
</Menu.ItemGroup>
<Menu.Separator />
<Menu.ItemGroup title="Align">
<Menu.Item value="left">Left</Menu.Item>
<Menu.Item value="middle">Middle</Menu.Item>
<Menu.Item value="right">Right</Menu.Item>
</Menu.ItemGroup>
</Menu.Content>
</Menu.Root>
</Box> Icon And Command Accessibility
<Box>
<Menu.Root>
<Menu.Button>Edit</Menu.Button>
<Menu.Content>
<Menu.Item value="cut" valueText="cut">
<Icon as={Scissors} size="xs" />
<Text as="span" class="flex-1">Cut</Text>
<Menu.ItemCommand>⌘X</Menu.ItemCommand>
</Menu.Item>
<Menu.Item value="copy" valueText="copy">
<Icon as={Copy} size="xs" />
<Text as="span" class="flex-1">Copy</Text>
<Menu.ItemCommand>⌘C</Menu.ItemCommand>
</Menu.Item>
<Menu.Item value="paste" valueText="paste">
<Icon as={ClipboardText} size="xs" />
<Text as="span" class="flex-1">Paste</Text>
<Menu.ItemCommand>⌘V</Menu.ItemCommand>
</Menu.Item>
</Menu.Content>
</Menu.Root>
</Box> Links Accessibility
Menu.ItemLink.
<Box>
<Menu.Root>
<Menu.Button>Select Anime</Menu.Button>
<Menu.Content>
<Menu.ItemLink
value="naruto"
href="https://www.crunchyroll.com/naruto"
target="_blank"
rel="noreferrer"
>
Naruto
</Menu.ItemLink>
<Menu.ItemLink
value="one-piece"
href="https://www.crunchyroll.com/one-piece"
target="_blank"
rel="noreferrer"
>
One Piece
</Menu.ItemLink>
<Menu.ItemLink
value="attack-on-titan"
href="https://www.crunchyroll.com/attack-on-titan"
target="_blank"
rel="noreferrer"
>
Attack on Titan
</Menu.ItemLink>
</Menu.Content>
</Menu.Root>
</Box> Mixed Layout Accessibility
<Box>
<Menu.Root>
<Menu.Button>Open</Menu.Button>
<Menu.Content>
<Flex class="grow gap-0">
<Menu.Item
value="cut"
class="w-14 flex-col justify-center gap-1"
>
<Icon as={Scissors} size="xs" />
Cut
</Menu.Item>
<Menu.Item
value="copy"
class="w-14 flex-col justify-center gap-1"
>
<Icon as={Copy} size="xs" />
Copy
</Menu.Item>
<Menu.Item
value="paste"
class="w-14 flex-col justify-center gap-1"
>
<Icon as={ClipboardText} size="xs" />
Paste
</Menu.Item>
</Flex>
<Menu.Item value="look-up">
<Text as="span" class="flex-1">Look Up</Text>
<Icon as={MagnifyingGlass} size="xs" />
</Menu.Item>
<Menu.Item value="translate">
<Text as="span" class="flex-1">Translate</Text>
<Icon as={Translate} size="xs" />
</Menu.Item>
<Menu.Item value="share">
<Text as="span" class="flex-1">Share</Text>
<Icon as={ShareNetwork} size="xs" />
</Menu.Item>
</Menu.Content>
</Menu.Root>
</Box> Placement Accessibility
positioning.placement to control menu placement relative to the trigger.
<Box>
<Menu.Root positioning={{ placement: "right-start" }}>
<Menu.Button>Open</Menu.Button>
<Menu.Content>
<Menu.Item value="new-txt">New Text File</Menu.Item>
<Menu.Item value="new-file">New File...</Menu.Item>
<Menu.Item value="new-win">New Window</Menu.Item>
<Menu.Item value="open-file">Open File...</Menu.Item>
<Menu.Item value="export">Export</Menu.Item>
</Menu.Content>
</Menu.Root>
</Box> Radio Accessibility
Menu.RadioItemGroup.
<Box>
<Menu.Root>
<Menu.Button>
<Icon as={SortAscending} size="sm" /> Sort
</Menu.Button>
<Menu.Content>
<Menu.RadioItemGroup value="asc">
<Menu.RadioItem value="asc">Ascending</Menu.RadioItem>
<Menu.RadioItem value="desc">Descending</Menu.RadioItem>
</Menu.RadioItemGroup>
</Menu.Content>
</Menu.Root>
</Box> Sizes Accessibility
size prop to control the size of the menu. Available sizes: sm, md.
<Box>
<HStack align="start" gap={8}>
{#each menuSizes as size}
<VStack gap={2} class="items-center">
<Text size="xs">{size}</Text>
<Menu.Root {size}>
<Menu.Button>Open</Menu.Button>
<Menu.Content>
<Menu.Item value="new-txt">New Text File</Menu.Item>
<Menu.Item value="new-file">New File...</Menu.Item>
<Menu.Item value="new-win">New Window</Menu.Item>
<Menu.Item value="open-file">Open File...</Menu.Item>
<Menu.Item value="export">Export</Menu.Item>
</Menu.Content>
</Menu.Root>
</VStack>
{/each}
</HStack>
</Box>Props
Menu.Root
The root container component that provides context for the menu.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The menu content. |
id | string | - | The unique identifier for the menu. If not provided, a unique ID will be auto-generated. |
size | "sm" | "md" | "md" | The size of the menu. |
colour | ColourName | "indigo" | The colour palette for highlighted items. |
open | boolean | - | Whether the menu is open. |
closeOnSelect | boolean | true | Whether to close the menu when an option is selected. |
loopFocus | boolean | false | Whether to loop the keyboard navigation. |
onPrefetch | (value: string) => void | - | Callback invoked when hovering over an item (for prefetching content). Similar to Astro's link prefetching, this allows preloading data before selection. |
Menu.Button
The button that triggers the menu to open.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The button content. |
class | string | - | Additional CSS classes to apply. |
variant | "solid" | "subtle" | "outline" | "ghost" | "plain" | "breadcrumb" | "outline" | The visual style of the button. |
size | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "md" | The size of the button. |
colour | ColourName | "gray" | The colour palette of the button. |
showIndicator | boolean | false | Whether to show the dropdown indicator. |
asChild | boolean | - | Whether to render as a child element. |
style | string | - | Additional inline styles. |
Menu.Content
The container for menu items that appears when the menu is open.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The menu content. |
class | string | - | Additional CSS classes to apply. |
portal | boolean | true | Whether to render the menu in a portal. |
Menu.Item
A single menu item that can be selected.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The menu item content. |
value | string | - | The unique value of the menu item. |
class | string | - | Additional CSS classes to apply. |
disabled | boolean | - | Whether the menu item is disabled. |
Menu.ItemLink
A menu item that renders as a navigation link.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The link text. |
value | string | - | The unique value of the menu item. |
href | string | - | The URL to navigate to. |
target | string | - | Where to open the link. |
rel | string | - | Relationship of the linked URL. |
class | string | - | Additional CSS classes to apply. |
Menu.ItemCommand
Displays a keyboard shortcut alongside a menu item.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The command content (keyboard shortcut). |
class | string | - | Additional CSS classes to apply. |
Menu.ItemGroup
Groups related menu items together with an optional label.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The menu item group content. |
title | string | - | The group title/label. |
class | string | - | Additional CSS classes to apply. |
Menu.Separator
A visual separator between menu items.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | - | Additional CSS classes to apply. |
Menu.TriggerItem
A menu item that opens a submenu when hovered or selected.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The trigger item content. |
value | string | - | The unique value of the menu item. |
class | string | - | Additional CSS classes to apply. |
Menu.ContextTrigger
A trigger that opens the menu on right-click (context menu).
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The context trigger content. |
class | string | - | Additional CSS classes to apply. |
Menu.CheckboxItem
A menu item with a checkbox for multi-selection options.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The checkbox item content. |
value | string | - | The unique value of the checkbox item. |
checked | boolean | - | Whether the checkbox is checked. |
class | string | - | Additional CSS classes to apply. |
showIndicator | boolean | true | Whether to show the checkbox indicator. |
startElement | Snippet | - | Element to render at the start of the item (for custom content, overrides showIndicator). |
disabled | boolean | - | Whether the checkbox item is disabled. |
Menu.RadioItemGroup
Groups radio items together for single-selection options.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The radio item group content. |
value | string | - | The controlled value of the radio group. |
onValueChange | (details: { value: string }) => void | - | Handler called when the value changes. |
class | string | - | Additional CSS classes to apply. |
Menu.RadioItem
A menu item with a radio button for single-selection within a group.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The radio item content. |
value | string | - | The unique value of the radio item. |
class | string | - | Additional CSS classes to apply. |
showIndicator | boolean | true | Whether to show the radio indicator. |
startElement | Snippet | - | Element to render at the start of the item (for custom content, overrides showIndicator). |
disabled | boolean | - | Whether the radio item is disabled. |
Menu.ItemIndicator
The indicator element shown for checked checkbox or radio items.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | Custom indicator content. |
class | string | - | Additional CSS classes to apply. |