DropdownMenu
A menu of actions that opens from a button, like the actions of an entry in the dashboard.
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuTrigger
} from 'alinea/components'
import {
IcBaselineContentCopy,
IcRoundArchive,
IcRoundDelete,
IcRoundEdit,
IcRoundMoreHoriz
} from 'alinea/dashboard/icons'
export function DropdownMenuExample() {
return (
<DropdownMenu>
<DropdownMenuTrigger
variant="outline"
size="icon"
icon={IcRoundMoreHoriz}
aria-label="Entry actions"
/>
<DropdownMenuContent align="start" aria-label="Entry actions">
<DropdownMenuItem icon={IcRoundEdit} onSelect={() => {}}>
Rename
<DropdownMenuShortcut>⌘R</DropdownMenuShortcut>
</DropdownMenuItem>
<DropdownMenuItem icon={IcBaselineContentCopy}>
Duplicate
</DropdownMenuItem>
<DropdownMenuItem icon={IcRoundArchive} disabled>
Archive
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem icon={IcRoundDelete} variant="destructive">
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}Checkbox and radio items
A menu can hold options as well: a checkbox item toggles one, a radio group picks one of several. Unlike actions they keep the menu open when selected.
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger
} from 'alinea/components'
import {IcRoundFilterList} from 'alinea/dashboard/icons'
import {useState} from 'react'
export function DropdownMenuSelectionExample() {
const [drafts, setDrafts] = useState(true)
const [archived, setArchived] = useState(false)
const [sort, setSort] = useState('updated')
return (
<DropdownMenu>
<DropdownMenuTrigger variant="outline" icon={IcRoundFilterList}>
View
</DropdownMenuTrigger>
<DropdownMenuContent aria-label="View options">
<DropdownMenuGroup aria-label="Show">
<DropdownMenuLabel>Show</DropdownMenuLabel>
<DropdownMenuCheckboxItem
checked={drafts}
onCheckedChange={setDrafts}
>
Drafts
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
checked={archived}
onCheckedChange={setArchived}
>
Archived entries
</DropdownMenuCheckboxItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuLabel>Sort by</DropdownMenuLabel>
<DropdownMenuRadioGroup
value={sort}
onValueChange={setSort}
aria-label="Sort by"
>
<DropdownMenuRadioItem value="updated">
Last updated
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="title">Title</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
)
}Props
<DropdownMenu>
<DropdownMenuTrigger>
Accepts every prop of Button.
<DropdownMenuContent>
Also accepts className and style, id and aria-* labelling attributes and data-* attributes.
<DropdownMenuItem>
Also accepts className and style and data-* attributes.
<DropdownMenuCheckboxItem>
Also accepts className and style and data-* attributes.
<DropdownMenuRadioGroup>
Also accepts id and aria-* labelling attributes.
<DropdownMenuRadioItem>
Also accepts className and style and data-* attributes.
<DropdownMenuGroup>
Also accepts id and aria-* labelling attributes.
<DropdownMenuLabel>
Also accepts className and style.
<DropdownMenuSeparator>
<DropdownMenuShortcut>
Also accepts className and style.
<DropdownMenuSub>
<DropdownMenuSubTrigger>
Also accepts className and style and data-* attributes.
<DropdownMenuSubContent>
Also accepts className and style, id and aria-* labelling attributes and data-* attributes.
Accessibility
The menu opens with Enter, Space or the arrow keys, the arrow keys move through its items and typing jumps to a matching item. Escape closes it and returns focus to the trigger.