Skip to content
VinUIComponentsDropdown Menu

Dropdown Menu

A list of actions or options that opens from a button. Same markup and props in every style: switch the style in the header to see it change.

Basic

An account menu with a heading, shortcuts and a sign-out at the end. In HTML it's a popover; vinui.js adds the keyboard.

With icons

An icon button that opens a menu lined up with its end.

Checkboxes and radios

Options that stay open as you change them.

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add dropdown-menu
React
import { DropdownMenu, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator } from "@/components/vin/dropdown-menu";
Vue
import DropdownMenu, { DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator } from "@/components/vin/dropdown-menu.vue";
Svelte
import DropdownMenu from "$lib/components/vin/dropdown-menu.svelte";
import DropdownMenuCheckboxItem from "$lib/components/vin/dropdown-menu-checkbox-item.svelte";
import DropdownMenuItem from "$lib/components/vin/dropdown-menu-item.svelte";
import DropdownMenuLabel from "$lib/components/vin/dropdown-menu-label.svelte";
import DropdownMenuRadioGroup from "$lib/components/vin/dropdown-menu-radio-group.svelte";
import DropdownMenuRadioItem from "$lib/components/vin/dropdown-menu-radio-item.svelte";
import DropdownMenuSeparator from "$lib/components/vin/dropdown-menu-separator.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/dropdown-menu.json, which every framework version is tested against.

PropValuesDefaultIn HTML
trigger
The button that opens it.
ReactElement—button[popovertarget="id"]
sidetopbottombottomdata-side on .vin-menu
alignstartcenterendstartdata-align on .vin-menu
DropdownMenuItem{ onSelect, icon, shortcut, danger, disabled }—button.vin-menu__item[role=menuitem] (.vin-menu__item--danger)
DropdownMenuCheckboxItem{ checked, defaultChecked, onCheckedChange }—button.vin-menu__item[role=menuitemcheckbox][aria-checked]
DropdownMenuRadioGroup / DropdownMenuRadioItem{ value, defaultValue, onValueChange } / { value }—div[role=group] > button.vin-menu__item[role=menuitemradio][aria-checked]
DropdownMenuLabel / DropdownMenuSeparatorboolean—.vin-menu__label, .vin-menu__separator[role=separator]

Parts

React, Vue, SvelteHTML classes
<DropdownMenu><DropdownMenuItem><DropdownMenuCheckboxItem><DropdownMenuRadioGroup><DropdownMenuRadioItem><DropdownMenuLabel><DropdownMenuSeparator>.vin-menu.vin-menu__item.vin-menu__item--danger.vin-menu__label.vin-menu__separator.vin-menu__shortcut

Accessibility

  • role="menu" with menuitem, menuitemcheckbox and menuitemradio items. The trigger says it opens a menu and whether it's open.
  • Enter, Space or Down Arrow opens it on the first item; Up Arrow opens it on the last.
  • Arrow keys move, Home and End jump, typing a letter goes to the next item that starts with it. Escape or Tab closes it and returns focus to the trigger.
  • Only one item is in the tab order at a time, so Tab leaves the menu instead of walking through it.