DropdownMenu
<script setup lang="ts">
import { Icon } from '@iconify/vue'
import { ref } from 'vue'
import {
DropdownMenuArrow,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuItemIndicator,
DropdownMenuLabel,
DropdownMenuPortal,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuRoot,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from 'radix-vue'
const toggleState = ref(false)
const checkboxOne = ref(false)
const checkboxTwo = ref(false)
const person = ref('pedro')
function handleClick() {
alert('hello!')
}
</script>
<template>
<DropdownMenuRoot v-model:open="toggleState">
<DropdownMenuTrigger
class="rounded-full w-[35px] h-[35px] inline-flex items-center justify-center text-grass11 bg-white shadow-[0_2px_10px] shadow-blackA7 outline-none hover:bg-green3 focus:shadow-[0_0_0_2px] focus:shadow-black"
aria-label="Customise options"
>
<Icon icon="radix-icons:hamburger-menu" />
</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent
class="min-w-[220px] outline-none bg-white rounded-md p-[5px] shadow-[0px_10px_38px_-10px_rgba(22,_23,_24,_0.35),_0px_10px_20px_-15px_rgba(22,_23,_24,_0.2)] will-change-[opacity,transform] data-[side=top]:animate-slideDownAndFade data-[side=right]:animate-slideLeftAndFade data-[side=bottom]:animate-slideUpAndFade data-[side=left]:animate-slideRightAndFade"
:side-offset="5"
>
<DropdownMenuItem
value="New Tab"
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
@click="handleClick"
>
New Tab
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⌘+T
</div>
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger
value="more toolsz"
class="group w-full text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[state=open]:bg-green4 data-[state=open]:text-grass11 data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1 data-[highlighted]:data-[state=open]:bg-green9 data-[highlighted]:data-[state=open]:text-green1"
>
More Tools
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
<Icon icon="radix-icons:chevron-right" />
</div>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent
class="min-w-[220px] outline-none bg-white rounded-md p-[5px] shadow-[0px_10px_38px_-10px_rgba(22,_23,_24,_0.35),_0px_10px_20px_-15px_rgba(22,_23,_24,_0.2)] will-change-[opacity,transform] data-[side=top]:animate-slideDownAndFade data-[side=right]:animate-slideLeftAndFade data-[side=bottom]:animate-slideUpAndFade data-[side=left]:animate-slideRightAndFade"
:side-offset="2"
:align-offset="-5"
>
<DropdownMenuItem
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Save Page As…
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⌘+S
</div>
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Create Shortcut…
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Name Window…
</DropdownMenuItem>
<DropdownMenuSeparator class="h-[1px] bg-green6 m-[5px]" />
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Developer Tools
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuItem
value="New Window"
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
New Window
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⌘+N
</div>
</DropdownMenuItem>
<DropdownMenuItem
value="New Private Window"
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
disabled
>
New Private Window
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⇧+⌘+N
</div>
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger
value="more tools"
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none w-full outline-none data-[state=open]:bg-green4 data-[state=open]:text-grass11 data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1 data-[highlighted]:data-[state=open]:bg-green9 data-[highlighted]:data-[state=open]:text-green1"
>
More Tools
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
<Icon icon="radix-icons:chevron-right" />
</div>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent
class="min-w-[220px] outline-none bg-white rounded-md p-[5px] shadow-[0px_10px_38px_-10px_rgba(22,_23,_24,_0.35),_0px_10px_20px_-15px_rgba(22,_23,_24,_0.2)] will-change-[opacity,transform] data-[side=top]:animate-slideDownAndFade data-[side=right]:animate-slideLeftAndFade data-[side=bottom]:animate-slideUpAndFade data-[side=left]:animate-slideRightAndFade"
:side-offset="2"
:align-offset="-5"
>
<DropdownMenuItem
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Save Page As…
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⌘+S
</div>
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Create Shortcut…
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Name Window…
</DropdownMenuItem>
<DropdownMenuSeparator class="h-[1px] bg-green6 m-[5px]" />
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Developer Tools
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger
value="more toolsz"
class="group w-full text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[state=open]:bg-green4 data-[state=open]:text-grass11 data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1 data-[highlighted]:data-[state=open]:bg-green9 data-[highlighted]:data-[state=open]:text-green1"
>
More Tools
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
<Icon icon="radix-icons:chevron-right" />
</div>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent
class="min-w-[220px] outline-none bg-white rounded-md p-[5px] shadow-[0px_10px_38px_-10px_rgba(22,_23,_24,_0.35),_0px_10px_20px_-15px_rgba(22,_23,_24,_0.2)] will-change-[opacity,transform] data-[side=top]:animate-slideDownAndFade data-[side=right]:animate-slideLeftAndFade data-[side=bottom]:animate-slideUpAndFade data-[side=left]:animate-slideRightAndFade"
:side-offset="2"
:align-offset="-5"
>
<DropdownMenuItem
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Save Page As…
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⌘+S
</div>
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Create Shortcut…
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Name Window…
</DropdownMenuItem>
<DropdownMenuSeparator class="h-[1px] bg-green6 m-[5px]" />
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Developer Tools
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger
value="more toolsz"
class="group w-full text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[state=open]:bg-green4 data-[state=open]:text-grass11 data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1 data-[highlighted]:data-[state=open]:bg-green9 data-[highlighted]:data-[state=open]:text-green1"
>
More Tools
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
<Icon icon="radix-icons:chevron-right" />
</div>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent
class="min-w-[220px] outline-none bg-white rounded-md p-[5px] shadow-[0px_10px_38px_-10px_rgba(22,_23,_24,_0.35),_0px_10px_20px_-15px_rgba(22,_23,_24,_0.2)] will-change-[opacity,transform] data-[side=top]:animate-slideDownAndFade data-[side=right]:animate-slideLeftAndFade data-[side=bottom]:animate-slideUpAndFade data-[side=left]:animate-slideRightAndFade"
:side-offset="2"
:align-offset="-5"
>
<DropdownMenuItem
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Save Page As…
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⌘+S
</div>
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Create Shortcut…
</DropdownMenuItem>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Name Window…
</DropdownMenuItem>
<DropdownMenuSeparator class="h-[1px] bg-green6 m-[5px]" />
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Developer Tools
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
Developer Tools
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuSeparator class="h-[1px] bg-green6 m-[5px]" />
<DropdownMenuCheckboxItem
v-model:checked="checkboxOne"
class="group text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
<DropdownMenuItemIndicator class="absolute left-0 w-[25px] inline-flex items-center justify-center">
<Icon icon="radix-icons:check" />
</DropdownMenuItemIndicator>
Show Bookmarks
<div
class="ml-auto pl-[20px] text-mauve11 group-data-[highlighted]:text-white group-data-[disabled]:text-mauve8"
>
⌘+B
</div>
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
v-model:checked="checkboxTwo"
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
>
<DropdownMenuItemIndicator class="absolute left-0 w-[25px] inline-flex items-center justify-center">
<Icon icon="radix-icons:check" />
</DropdownMenuItemIndicator>
Show Full URLs
</DropdownMenuCheckboxItem>
<DropdownMenuSeparator class="h-[1px] bg-green6 m-[5px]" />
<DropdownMenuLabel class="pl-[25px] text-xs leading-[25px] text-mauve11">
People
</DropdownMenuLabel>
<DropdownMenuRadioGroup v-model="person">
<DropdownMenuRadioItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
value="pedro"
>
<DropdownMenuItemIndicator class="absolute left-0 w-[25px] inline-flex items-center justify-center">
<Icon icon="radix-icons:dot-filled" />
</DropdownMenuItemIndicator>
Pedro Duarte
</DropdownMenuRadioItem>
<DropdownMenuRadioItem
class="text-[13px] leading-none text-grass11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-green9 data-[highlighted]:text-green1"
value="colm"
>
<DropdownMenuItemIndicator class="absolute left-0 w-[25px] inline-flex items-center justify-center">
<Icon icon="radix-icons:dot-filled" />
</DropdownMenuItemIndicator>
Colm Tuite
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
<DropdownMenuArrow class="fill-white" />
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
Features
- Can be controlled or uncontrolled.
- Supports submenus with configurable reading direction.
- Supports items, labels, groups of items.
- Supports checkable items (single or multiple) with optional indeterminate state.
- Supports modal and non-modal modes.
- Customize side, alignment, offsets, collision handling.
- Optionally render a pointing arrow.
- Focus is fully managed.
- Full keyboard navigation.
- Typeahead support.
- Dismissing and layering behavior is highly customizable.
Installation
Install the component from your command line.
npm install radix-vue
Anatomy
Import all parts and piece them together.
<script setup lang="ts">
import {
DropdownMenuArrow,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuItemIndicator,
DropdownMenuLabel,
DropdownMenuPortal,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuRoot,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger />
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuLabel />
<DropdownMenuItem />
<DropdownMenuGroup>
<DropdownMenuItem />
</DropdownMenuGroup>
<DropdownMenuCheckboxItem>
<DropdownMenuItemIndicator />
</DropdownMenuCheckboxItem>
<DropdownMenuRadioGroup>
<DropdownMenuRadioItem>
<DropdownMenuItemIndicator />
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
<DropdownMenuSub>
<DropdownMenuSubTrigger />
<DropdownMenuPortal>
<DropdownMenuSubContent />
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuSeparator />
<DropdownMenuArrow />
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
API Reference
Root
Contains all the parts of a dropdown menu.
Prop | Default | Type |
---|---|---|
defaultOpen | boolean The open state of the dropdown menu when it is initially rendered. Use when you do not need to control its open state. | |
open | boolean The controlled open state of the dropdown menu. Must be used in conjunction with | |
modal | true | boolean The modality of the dropdown menu. When set to |
dir | enum The reading direction of submenus when applicable. If omitted, inherits globally from |
Emit | Type |
---|---|
@update:open | (open: boolean) => void |
Trigger
The button that toggles the dropdown menu. By default, the DropdownMenuContent
will position itself against the trigger.
Prop | Default | Type |
---|---|---|
as | button | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Data Attribute | Value |
---|---|
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
Portal
When used, portals the content part into the body
.
Prop | Default | Type |
---|---|---|
to | body | string | HTMLElement Vue native teleport component props. (to) |
Content
The component that pops out when the dropdown menu is open.
Prop | Default | Type |
---|---|---|
loop | false | boolean When |
forceMount | boolean Used to force mounting when more control is needed. Useful when controlling animation with Vue.js animation libraries. It inherits from | |
side | "bottom" | enum The preferred side of the trigger to render against when open. Will be reversed when collisions occur and |
sideOffset | 0 | number The distance in pixels from the trigger. |
align | "center" | enum The preferred alignment against the trigger. May change when collisions occur. |
alignOffset | 0 | number An offset in pixels from the |
avoidCollisions | true | boolean When |
collisionBoundary | [] | Boundary The 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. |
collisionPadding | 0 | number | Padding The 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: |
arrowPadding | 0 | number The padding between the arrow and the edges of the content. If your content has |
sticky | "partial" | enum The sticky behavior on the align axis. |
hideWhenDetached | false | boolean Whether to hide the content when the trigger becomes fully occluded. |
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Emit | Type |
---|---|
@closeAutoFocus | (event: Event) => void |
@escapeKeyDown | (event: KeyboardEvent) => void |
@pointerDownOutside | (event: PointerDownOutsideEvent) => void |
@focusOutside | (event: FocusOutsideEvent) => void |
@interactOutside | (event: FocusEvent | MouseEvent | TouchEvent) => void |
Data Attribute | Value |
---|---|
[data-state] | "open" | "closed" |
[data-side] | "left" | "right" | "bottom" | "top" |
[data-align] | "start" | "end" | "center" |
[data-orientation] | "vertical" | "horizontal" |
CSS Variable | Description |
---|---|
--radix-dropdown-menu-content-transform-origin | The transform-origin computed from the content and arrow positions/offsets |
--radix-dropdown-menu-content-available-width | The remaining width between the trigger and the boundary edge |
--radix-dropdown-menu-content-available-height | The remaining height between the trigger and the boundary edge |
--radix-dropdown-menu-trigger-width | The width of the trigger |
--radix-dropdown-menu-trigger-height | The height of the trigger |
Arrow
An optional arrow element to render alongside the dropdown menu. This can be used to help visually link the trigger with the DropdownMenuContent
. Must be rendered inside DropdownMenuContent
.
Prop | Default | Type |
---|---|---|
width | 10 | number The width of the arrow in pixels. |
height | 5 | number The height of the arrow in pixels. |
as | svg | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Item
The component that contains the dropdown menu items.
Prop | Default | Type |
---|---|---|
disabled | boolean When | |
textValue | string Optional text used for typeahead purposes. By default the typeahead behavior will use the | |
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Emit | Type |
---|---|
@select | (event: Event) => void |
Data Attribute | Value |
---|---|
[data-orientation] | "vertical" | "horizontal" |
[data-highlighted] | Present when highlighted |
[data-disabled] | Present when disabled |
Group
Used to group multiple DropdownMenuItem
s.
Prop | Default | Type |
---|---|---|
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Label
Used to render a label. It won't be focusable using arrow keys.
Prop | Default | Type |
---|---|---|
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
CheckboxItem
An item that can be controlled and rendered like a checkbox.
Prop | Default | Type |
---|---|---|
checked | boolean | 'indeterminate' The controlled checked state of the item. Must be used in conjunction with | |
disabled | boolean When | |
textValue | string Optional text used for typeahead purposes. By default the typeahead behavior will use the | |
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Emit | Type |
---|---|
@update:checked | (checked: boolean) => void |
@select | (event: Event) => void |
Data Attribute | Value |
---|---|
[data-state] | "checked" | "unchecked" | "indeterminate" |
[data-highlighted] | Present when highlighted |
[data-disabled] | Present when disabled |
RadioGroup
Used to group multiple DropdownMenuRadioItem
s.
Prop | Default | Type |
---|---|---|
modelValue | string The value of the selected item in the group. | |
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Emit | Type |
---|---|
@update:modelValue | (value: string) => void |
RadioItem
An item that can be controlled and rendered like a radio.
Prop | Default | Type |
---|---|---|
value* | string The unique value of the item. | |
disabled | boolean When | |
textValue | string Optional text used for typeahead purposes. By default the typeahead behavior will use the | |
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Emit | Type |
---|---|
@select | (event: Event) => void |
Data Attribute | Value |
---|---|
[data-state] | "checked" | "unchecked" | "indeterminate" |
[data-highlighted] | Present when highlighted |
[data-disabled] | Present when disabled |
ItemIndicator
Renders when the parent DropdownMenuCheckboxItem
or DropdownMenuRadioItem
is checked. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.
Prop | Default | Type |
---|---|---|
as | span | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
forceMount | boolean Used to force mounting when more control is needed. Useful when controlling animation with Vue.js animation libraries. |
Data Attribute | Value |
---|---|
[data-state] | "checked" | "unchecked" | "indeterminate" |
Separator
Used to visually separate items in the dropdown menu.
Prop | Default | Type |
---|---|---|
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Sub
Contains all the parts of a submenu.
Prop | Default | Type |
---|---|---|
open | boolean The controlled open state of the submenu. Must be used in conjunction with | |
defaultOpen | boolean The open state of the submenu when it is initially rendered. Use when you do not need to control its open state. |
Emit | Type |
---|---|
@update:open | (open: boolean) => void |
SubTrigger
An item that opens a submenu. Must be rendered inside DropdownMenuSub
.
Prop | Default | Type |
---|---|---|
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
disabled | boolean
When | |
textValue | string
Optional text used for typeahead purposes. By default the typeahead
behavior will use the |
Data Attribute | Value |
---|---|
[data-state] | "open" | "closed" |
[data-highlighted] | Present when highlighted |
[data-disabled] | Present when disabled |
CSS Variable | Description |
---|---|
--radix-dropdown-menu-content-transform-origin | The transform-origin computed from the content and arrow positions/offsets |
--radix-dropdown-menu-content-available-width |
The remaining width between the trigger and the boundary edge
|
--radix-dropdown-menu-content-available-height | The remaining height between the trigger and the boundary edge |
--radix-dropdown-menu-trigger-width | The width of the trigger |
--radix-dropdown-menu-trigger-height | The height of the trigger |
SubContent
The component that pops out when a submenu is open. Must be rendered inside DropdownMenuSub
.
Prop | Default | Type |
---|---|---|
loop | false | boolean
When |
forceMount | boolean
Used to force mounting when more control is needed. Useful when
controlling animation with Vue.js animation libraries. It inherits from{' '}
| |
sideOffset | 0 | number The distance in pixels from the trigger. |
alignOffset | 0 | number
An offset in pixels from the |
avoidCollisions | true | boolean
When |
collisionBoundary | [] | Boundary The 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. |
collisionPadding | 0 | number | Padding
The 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: |
arrowPadding | 0 | number
The padding between the arrow and the edges of the content. If your
content has |
sticky | "partial" | enum
The sticky behavior on the align axis. |
hideWhenDetached | false | boolean Whether to hide the content when the trigger becomes fully occluded. |
as | div | string | Component The element or component this component should render as. Can be overwrite by |
asChild | false | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. |
Emit | Type |
---|---|
@escapeKeyDown | (event: KeyboardEvent) => void |
@pointerDownOutside | (event: PointerDownOutsideEvent) => void |
@focusOutside | (event: FocusOutsideEvent) => void |
@interactOutside | (event: FocusEvent | MouseEvent | TouchEvent) => void |
Data Attribute | Value |
---|---|
[data-state] | "open" | "closed" |
[data-side] | "left" | "right" | "bottom" | "top" |
[data-align] | "start" | "end" | "center" |
[data-orientation] | "vertical" | "horizontal" |
Examples
With submenus
You can create submenus by using DropdownMenuSub
in combination with its parts.
<script setup lang="ts">
import {
DropdownMenuArrow,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuPortal,
DropdownMenuRoot,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuSub>
<DropdownMenuSubTrigger>Sub menu →</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
<DropdownMenuItem>Sub menu item</DropdownMenuItem>
<DropdownMenuItem>Sub menu item</DropdownMenuItem>
<DropdownMenuArrow />
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuSeparator />
<DropdownMenuItem>…</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
With disabled items
You can add special styles to disabled items via the data-disabled
attribute.
<script setup lang="ts">
import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuPortal,
DropdownMenuRoot,
DropdownMenuTrigger,
} from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuItem class="DropdownMenuItem" disabled>
…
</DropdownMenuItem>
<DropdownMenuItem class="DropdownMenuItem">
…
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
/* styles.css */
.DropdownMenuItem[data-disabled] {
color: gainsboro;
}
With separators
Use the Separator
part to add a separator between items.
<script setup lang="ts">
import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuPortal,
DropdownMenuRoot,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>…</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
With labels
Use the Label
part to help label a section.
<script setup lang="ts">
import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuPortal,
DropdownMenuRoot,
DropdownMenuTrigger,
} from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuLabel>Label</DropdownMenuLabel>
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuItem>…</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
With checkbox items
Use the CheckboxItem
part to add an item that can be checked.
<script setup lang="ts">
import { Icon } from '@iconify/vue'
import { ref } from 'vue'
import {
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuItemIndicator,
DropdownMenuPortal,
DropdownMenuRoot,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from 'radix-vue'
const checked = ref(false)
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuItem>…</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuCheckboxItem v-model:checked="checked">
<DropdownMenuItemIndicator>
<Icon icon="radix-icons:check" />
</DropdownMenuItemIndicator>
Checkbox item
</DropdownMenuCheckboxItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
With radio items
Use the RadioGroup
and RadioItem
parts to add an item that can be checked amongst others.
<script setup lang="ts">
import { Icon } from '@iconify/vue'
import { ref } from 'vue'
import {
DropdownMenuContent,
DropdownMenuItemIndicator,
DropdownMenuPortal,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuRoot,
DropdownMenuTrigger,
} from 'radix-vue'
const color = ref(false)
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuRadioGroup v-model="color">
<DropdownMenuRadioItem value="red">
<DropdownMenuItemIndicator>
<Icon icon="radix-icons:check" />
</DropdownMenuItemIndicator>
Red
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="blue">
<DropdownMenuItemIndicator>
<Icon icon="radix-icons:check" />
</DropdownMenuItemIndicator>
Blue
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="green">
<DropdownMenuItemIndicator>
<Icon icon="radix-icons:check" />
</DropdownMenuItemIndicator>
Green
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
With complex items
You can add extra decorative elements in the Item
parts, such as images.
<script setup lang="ts">
import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuPortal,
DropdownMenuRoot,
DropdownMenuTrigger,
} from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuItem>
<img src="…">
Adolfo Hess
</DropdownMenuItem>
<DropdownMenuItem>
<img src="…">
Miyah Myles
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
Constrain the content/sub-content size
You may want to constrain the width of the content (or sub-content) so that it matches the trigger (or sub-trigger) width. You may also want to constrain its height to not exceed the viewport.
We expose several CSS custom properties such as --radix-dropdown-menu-trigger-width
and --radix-dropdown-menu-content-available-height
to support this. Use them to constrain the content dimensions.
<script setup lang="ts">
import { DropdownMenuContent, DropdownMenuPortal, DropdownMenuRoot, DropdownMenuTrigger } from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent class="DropdownMenuContent" :side-offset="5">
…
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
/* styles.css */
.DropdownMenuContent {
width: var(--radix-dropdown-menu-trigger-width);
max-height: var(--radix-dropdown-menu-content-available-height);
}
Origin-aware animations
We expose a CSS custom property --radix-dropdown-menu-content-transform-origin
. Use it to animate the content from its computed origin based on side
, sideOffset
, align
, alignOffset
and any collisions.
<script setup lang="ts">
import { DropdownMenuContent, DropdownMenuPortal, DropdownMenuRoot, DropdownMenuTrigger } from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent class="DropdownMenuContent">
…
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
/* styles.css */
.DropdownMenuContent {
transform-origin: var(--radix-dropdown-menu-content-transform-origin);
animation: scaleIn 0.5s ease-out;
}
@keyframes scaleIn {
from {
opacity: 0;
transform: scale(0);
}
to {
opacity: 1;
transform: scale(1);
}
}
Collision-aware animations
We expose data-side
and data-align
attributes. Their values will change at runtime to reflect collisions. Use them to create collision and direction-aware animations.
<script setup lang="ts">
import { DropdownMenuContent, DropdownMenuPortal, DropdownMenuRoot, DropdownMenuTrigger } from 'radix-vue'
</script>
<template>
<DropdownMenuRoot>
<DropdownMenuTrigger>…</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent class="DropdownMenuContent">
…
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenuRoot>
</template>
/* styles.css */
.DropdownMenuContent {
animation-duration: 0.6s;
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}
.DropdownMenuContent[data-side="top"] {
animation-name: slideUp;
}
.DropdownMenuContent[data-side="bottom"] {
animation-name: slideDown;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes slideDown {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
Accessibility
Adheres to the Menu Button WAI-ARIA design pattern and uses roving tabindex to manage focus movement among menu items.
Keyboard Interactions
Key | Description |
---|---|
Space |
When focus is on DropdownMenuTrigger , opens the dropdown
menu and focuses the first item.
When focus is on an item, activates the focused item. |
Enter |
When focus is on DropdownMenuTrigger , opens the dropdown
menu and focuses the first item.
When focus is on an item, activates the focused item. |
ArrowDown |
When focus is on DropdownMenuTrigger , opens the dropdown
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.
|
ArrowRightArrowLeft |
When focus is on DropdownMenuSubTrigger , opens or closes
the submenu depending on reading direction.
|
Esc |
Closes the dropdown menu and moves focus to{' '}
DropdownMenuTrigger .
|
Custom APIs
Create your own API by abstracting the primitive parts into your own component.
Abstract the arrow and item indicators
This example abstracts the DropdownMenuArrow
and DropdownMenuItemIndicator
parts. It also wraps implementation details for CheckboxItem
and RadioItem
.
Usage
<script setup lang="ts">
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from './your-dropdown-menu'
</script>
<template>
<DropdownMenu>
<DropdownMenuTrigger>DropdownMenu trigger</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>Item</DropdownMenuItem>
<DropdownMenuLabel>Label</DropdownMenuLabel>
<DropdownMenuGroup>Group</DropdownMenuGroup>
<DropdownMenuCheckboxItem>CheckboxItem</DropdownMenuCheckboxItem>
<DropdownMenuSeparator>Separator</DropdownMenuSeparator>
<DropdownMenuRadioGroup>
<DropdownMenuRadioItem>RadioItem</DropdownMenuRadioItem>
<DropdownMenuRadioItem>RadioItem</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
</template>
Implementation
// your-dropdown-menu.ts
export { default as DropdownMenuContent } from 'DropdownMenuContent.vue'
export { default as DropdownMenuCheckboxItem } from 'DropdownMenuCheckboxItem.vue'
export { default as DropdownMenuRadioItem } from 'DropdownMenuRadioItem.vue'
export {
DropdownMenuRoot as DropdownMenu,
DropdownMenuTrigger,
DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuGroup,
DropdownMenuRadioGroup,
DropdownMenuSeparator
} from 'radix-vue'
<!-- DropdownMenuContent.vue -->
<script setup lang="ts">
import { DropdownMenuContent, type DropdownMenuContentEmits, type DropdownMenuContentProps, DropdownMenuPortal, useForwardPropsEmits, } from 'radix-vue'
const props = defineProps<DropdownMenuContentProps>()
const emits = defineEmits<DropdownMenuContentEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<DropdownMenuPortal>
<DropdownMenuContent v-bind="forwarded">
<slot />
</DropdownMenuContent>
</DropdownMenuPortal>
</template>
<!-- DropdownMenuCheckboxItem.vue -->
<script setup lang="ts">
import { DropdownMenuCheckboxItem, type DropdownMenuCheckboxItemEmits, type DropdownMenuCheckboxItemProps, DropdownMenuItemIndicator, useForwardPropsEmits } from 'radix-vue'
import { CheckIcon } from '@radix-icons/vue'
const props = defineProps<DropdownMenuCheckboxItemProps>()
const emits = defineEmits<DropdownMenuCheckboxItemEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<DropdownMenuCheckboxItem v-bind="forwarded">
<span>
<DropdownMenuItemIndicator>
<CheckIcon />
</DropdownMenuItemIndicator>
</span>
<slot />
</DropdownMenuCheckboxItem>
</template>
<!-- DropdownMenuRadioItem.vue -->
<script setup lang="ts">
import { DropdownMenuItemIndicator, DropdownMenuRadioItem, type DropdownMenuRadioItemEmits, type DropdownMenuRadioItemProps, useForwardPropsEmits, } from 'radix-vue'
import { DotFilledIcon } from '@radix-icons/vue'
const props = defineProps<DropdownMenuRadioItemProps>()
const emits = defineEmits<DropdownMenuRadioItemEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<DropdownMenuRadioItem v-bind="forwarded">
<span>
<DropdownMenuItemIndicator>
<DotFilledIcon />
</DropdownMenuItemIndicator>
</span>
<slot />
</DropdownMenuRadioItem>
</template>