Dropdown Menu
Displays a menu located at the trigger element.
Preview
Installation
npx sigma-ui@latest add dropdown-menuUsage
<script setup lang="ts">
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
</script>
<template>
<DropdownMenu>
<DropdownMenuTrigger>Open</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>My Account</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem>Profile</DropdownMenuItem>
<DropdownMenuItem>Billing</DropdownMenuItem>
<DropdownMenuItem>Team</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</template>- Use
as-childon<DropdownMenuTrigger>to render your own trigger, such as a<Button>. - Use
v-model:openon<DropdownMenu>to control the open state. - Use
<DropdownMenuCheckboxItem>withv-modeland<DropdownMenuRadioGroup>/<DropdownMenuRadioItem>for items with a checked state.
Examples
Basic
Checkboxes
Radio Group
API Reference
DropdownMenu
Props
| Prop | Type | Default |
|---|---|---|
defaultOpenThe open state of the dropdown menu when it is initially rendered. Use when you do not need to control its open state. | boolean | - |
openThe controlled open state of the menu. Can be used as | boolean | - |
dirThe reading direction of the combobox when applicable. If omitted, inherits globally from | Direction$4 | - |
modalThe modality of the dropdown menu. When set to | boolean | - |
Events
| Event | Payload |
|---|---|
update:open | [payload: boolean] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuTrigger
Props
| Prop | Type | Default |
|---|---|---|
disabledWhen | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuContent
Props
| Prop | Type | Default |
|---|---|---|
forceMountUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
loopWhen | boolean | false |
referenceThe custom element or virtual element that will be set as the reference to position the floating element. If provided, it will replace the default anchor element. | ReferenceElement | - |
memoDependenciesReactive dependencies that should invalidate the memoized content subtree. | unknown[] | - |
sideThe preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. | "top" | "right" | "bottom" | "left" | "bottom" |
sideOffsetThe distance in pixels from the trigger. | number | 4 |
sideFlipFlip to the opposite side when colliding with boundary. | boolean | true |
alignThe preferred alignment against the trigger. May change when collisions occur. | "center" | "start" | "end" | "center" |
alignOffsetAn offset in pixels from the | number | 0 |
alignFlipFlip alignment when colliding with boundary.
May only occur when | boolean | true |
avoidCollisionsWhen | boolean | true |
collisionBoundaryThe element used as the collision boundary. By default this is the viewport, though you can provide additional element(s) to be included in this check. | Element | (Element | null)[] | null | [] |
collisionPaddingThe distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }. | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 0 |
arrowPaddingThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. | number | 0 |
hideShiftedArrowWhen | boolean | true |
stickyThe sticky behavior on the align axis. | "partial" | "always" | "partial" |
hideWhenDetachedWhether to hide the content when the trigger becomes fully occluded. | boolean | false |
positionStrategyThe type of CSS position property to use. | "absolute" | "fixed" | - |
updatePositionStrategyStrategy to update the position of the floating element on every animation frame. | "always" | "optimized" | 'optimized' |
disableUpdateOnLayoutShiftWhether to disable the update position for the content when the layout shifted. | boolean | false |
prioritizePositionForce content to be position within the viewport. Might overlap the reference element, which may not be desired. | boolean | false |
Events
| Event | Payload |
|---|---|
escapeKeyDownEvent handler called when the escape key is down. Can be prevented. | [event: KeyboardEvent] |
pointerDownOutsideEvent handler called when a | [event: PointerDownOutsideEvent] |
focusOutsideEvent handler called when the focus moves outside of the | [event: FocusOutsideEvent] |
interactOutsideEvent handler called when an interaction happens outside the | [event: PointerDownOutsideEvent | FocusOutsideEvent] |
openAutoFocus | [event: Event] |
closeAutoFocusEvent handler called when auto-focusing on close. Can be prevented. | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuGroup
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuRadioGroup
Props
| Prop | Type | Default |
|---|---|---|
modelValueThe value of the selected item in the group. | AcceptableValue | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value changes. | [payload: AcceptableValue] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuItem
Props
| Prop | Type | Default |
|---|---|---|
disabledWhen | boolean | - |
textValueOptional text used for typeahead purposes. By default the typeahead behavior will use the | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
insetAdds left padding to align with items that have an icon or indicator. | boolean | - |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuCheckboxItem
Props
| Prop | Type | Default |
|---|---|---|
modelValueThe controlled checked state of the item. Can be used as | CheckedState | - |
disabledWhen | boolean | - |
textValueOptional text used for typeahead purposes. By default the typeahead behavior will use the | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the checked state changes. | [payload: boolean] |
selectEvent handler called when the user selects an item (via mouse or keyboard). <br>
Calling | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuRadioItem
Props
| Prop | Type | Default |
|---|---|---|
valuerequiredThe unique value of the item. | AcceptableValue | - |
disabledWhen | boolean | - |
textValueOptional text used for typeahead purposes. By default the typeahead behavior will use the | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Events
| Event | Payload |
|---|---|
selectEvent handler called when the user selects an item (via mouse or keyboard). <br>
Calling | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuShortcut
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuSeparator
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
DropdownMenuLabel
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
insetAdds left padding to align with items that have an icon or indicator. | boolean | - |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuSub
Props
| Prop | Type | Default |
|---|---|---|
defaultOpenThe open state of the dropdown menu when it is initially rendered. Use when you do not need to control its open state. | boolean | - |
openThe controlled open state of the menu. Can be used as | boolean | - |
Events
| Event | Payload |
|---|---|
update:openEvent handler called when the open state of the submenu changes. | [payload: boolean] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuSubTrigger
Props
| Prop | Type | Default |
|---|---|---|
graceDurationHow long (in milliseconds) the pointer is given to reach the submenu after leaving the trigger. While it moves towards the submenu within this time, hovering other items won't close the submenu. Increase it for users who move the pointer slowly or on devices under heavy load. | number | 300 |
disabledWhen | boolean | - |
textValueOptional text used for typeahead purposes. By default the typeahead behavior will use the | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
insetAdds left padding to align with items that have an icon or indicator. | boolean | - |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
DropdownMenuSubContent
Props
| Prop | Type | Default |
|---|---|---|
forceMountUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
loopWhen | boolean | false |
referenceThe custom element or virtual element that will be set as the reference to position the floating element. If provided, it will replace the default anchor element. | ReferenceElement | - |
memoDependenciesReactive dependencies that should invalidate the memoized content subtree. | unknown[] | - |
sideOffsetThe distance in pixels from the trigger. | number | 0 |
sideFlipFlip to the opposite side when colliding with boundary. | boolean | true |
alignOffsetAn offset in pixels from the | number | 0 |
alignFlipFlip alignment when colliding with boundary.
May only occur when | boolean | true |
avoidCollisionsWhen | boolean | true |
collisionBoundaryThe element used as the collision boundary. By default this is the viewport, though you can provide additional element(s) to be included in this check. | Element | (Element | null)[] | null | [] |
collisionPaddingThe distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }. | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 0 |
arrowPaddingThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. | number | 0 |
hideShiftedArrowWhen | boolean | true |
stickyThe sticky behavior on the align axis. | "partial" | "always" | "partial" |
hideWhenDetachedWhether to hide the content when the trigger becomes fully occluded. | boolean | false |
positionStrategyThe type of CSS position property to use. | "absolute" | "fixed" | - |
updatePositionStrategyStrategy to update the position of the floating element on every animation frame. | "always" | "optimized" | 'optimized' |
disableUpdateOnLayoutShiftWhether to disable the update position for the content when the layout shifted. | boolean | false |
prioritizePositionForce content to be position within the viewport. Might overlap the reference element, which may not be desired. | boolean | false |
Events
| Event | Payload |
|---|---|
escapeKeyDownEvent handler called when the escape key is down. Can be prevented. | [event: KeyboardEvent] |
pointerDownOutsideEvent handler called when a | [event: PointerDownOutsideEvent] |
focusOutsideEvent handler called when the focus moves outside of the | [event: FocusOutsideEvent] |
interactOutsideEvent handler called when an interaction happens outside the | [event: PointerDownOutsideEvent | FocusOutsideEvent] |
openAutoFocus | [event: Event] |
closeAutoFocusEvent handler called when auto-focusing on close. Can be prevented. | [event: Event] |
entryFocus | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Adheres to the Menu Button WAI-ARIA design pattern and uses roving focus to move between items. Reka UI manages focus and the menu / menuitem roles.
| Key | Description |
|---|---|
| Space | When focus is on the trigger, opens the menu and focuses the first item. When focus is on an item, activates it. |
| Enter | When focus is on the trigger, opens the menu and focuses the first item. When focus is on an item, activates it. |
| ArrowDown | When focus is on the trigger, opens the menu. When focus is on an item, moves focus to the next item. |
| ArrowUp | When focus is on an item, moves focus to the previous item. |
| ArrowRight | When focus is on a submenu trigger, opens the submenu. |
| ArrowLeft | When focus is on an item of a submenu, closes the submenu and moves focus to its trigger. |
| Esc | Closes the menu and moves focus to the trigger. |