Navigation
Dropdown Menu
A floating action menu with items, labels and separators.
<script>
import {
DropdownMenu,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
Button,
} from "@codeatlasdev/ui";
</script>
<DropdownMenu>
{#snippet triggerChild(props)}<Button {...props}>Open menu</Button>{/snippet}
<DropdownMenuLabel>File actions</DropdownMenuLabel>
<DropdownMenuItem onclick={edit}>{#snippet children()}Edit{/snippet}</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" onclick={remove}>{#snippet children()}Delete{/snippet}</DropdownMenuItem>
</DropdownMenu>
Keyboard support follows the WAI-ARIA menu pattern: Enter, Space or ArrowDown opens the menu on the first item, ArrowUp opens it on the last, arrows then move, Enter or Space selects, Escape closes and focus returns to the trigger. Tab closes the menu. Selecting an item closes it. The menu is a popover layer in the browser top layer, positioned with CSS anchor positioning where supported, so it stays on top of a dialog it is opened from. Pass an interactive trigger (Button, IconButton) through triggerChild and spread the received props on it. Use trigger only for non-interactive content such as text or an icon. Use DropdownMenuLabel for a non-interactive group heading and DropdownMenuSeparator for a divider.
Default
A button trigger with a label, items, a separator and a destructive item.
Code
Icon trigger
An IconButton trigger. IconButton needs an aria-label.
Code
DropdownMenu
| Prop | Type | Default | Description |
|---|---|---|---|
triggerChild | Snippet<[Record<string, unknown>]> | – | Interactive trigger. Receives the trigger props to spread onto your Button or IconButton. |
trigger | Snippet | – | Non-interactive trigger content (text, icon), wrapped in the menu's own button. |
children | Snippet | – | Menu content: items, labels and separators. |
side | 'top' | 'right' | 'bottom' | 'left' | 'bottom' | Preferred side of the trigger. |
align | 'start' | 'center' | 'end' | 'start' | Alignment against the trigger. |
sideOffset | number | 6 | Distance from the trigger in pixels. |
class | string | '' | Extra CSS classes on the content. |
DropdownMenuItem
| Prop | Type | Default | Description |
|---|---|---|---|
onclick | () => void | – | Called when the item is selected. |
variant | 'default' | 'destructive' | 'default' | destructive colors the item with the error token. |
disabled | boolean | false | Prevents selection. |
children | Snippet | – | Item content, usually an icon and a label. |
class | string | '' | Extra CSS classes. |
DropdownMenuLabel
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | – | Heading text. |
class | string | '' | Extra CSS classes. |
DropdownMenuSeparator takes no props.