DropdownMenu
Trigger-driven menu of contextual commands with menu semantics and keyboard item navigation.
Preview
A live, theme-aware example rendered with the published component.
Import
Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.
tsximport { DropdownMenu } from "@tavojs/ui/dropdown-menu";The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/dropdown-menu.
When to use
Use it when
Choose something else when
Examples
These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.
DropdownMenu example
tsximport { createTavo } from "@tavojs/core";
import { DropdownMenu } from "@tavojs/ui/dropdown-menu";
import { Text } from "@tavojs/ui";
type State = { copies: number };
export const DropdownMenuExample1 = createTavo<Record<string, never>, State>({
model: () => ({ copies: 0 }),
view: ({ state, model }) => (
<>
<DropdownMenu>
<DropdownMenu.Trigger>Actions</DropdownMenu.Trigger>
<DropdownMenu.Content>
<DropdownMenu.Item onSelect={() => model.set("copies", state.copies + 1)}>Duplicate</DropdownMenu.Item>
<DropdownMenu.Item href="/settings">Settings</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu>
<Text role="status">Copies created in this demo: {state.copies}</Text>
</>
)
});Common props and defaults
A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
open | boolean | — | Configures open for this component. |
defaultOpen | boolean | — | Configures defaultOpen for this component. |
align | "start" | "end" | — | Configures align for this component. |
onClose | () => void | — | Configures onClose for this component. |
onOpenChange | (open, reason) => void | — | Configures onOpenChange for this component. |
Complete TypeScript API
Import from @tavojs/ui/dropdown-menu. Published exports: DropdownMenu, DropdownMenuClose, DropdownMenuContent, DropdownMenuContentProps, DropdownMenuItem, DropdownMenuItemProps, DropdownMenuProps, DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuTriggerProps.
DropdownMenuProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by DropdownMenu. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by DropdownMenu. |
id | string | No | Inherited id attribute accepted by DropdownMenu. |
role | string | No | Inherited role attribute accepted by DropdownMenu. |
style | Record<string, unknown> | No | Inherited style attribute accepted by DropdownMenu. |
title | string | No | Inherited title attribute accepted by DropdownMenu. |
tabIndex | number | No | Inherited tabIndex attribute accepted by DropdownMenu. |
hidden | boolean | No | Inherited hidden attribute accepted by DropdownMenu. |
disabled | boolean | No | Inherited disabled attribute accepted by DropdownMenu. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by DropdownMenu. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by DropdownMenu. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by DropdownMenu. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by DropdownMenu. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by DropdownMenu. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by DropdownMenu. |
open | boolean | No | Configures open for this component. |
defaultOpen | boolean | No | Configures defaultOpen for this component. |
align | "start" | "end" | No | Configures align for this component. |
onClose | () => void | No | Configures onClose for this component. |
onOpenChange | (open: boolean, reason: DisclosureOpenChangeReason) => void | No | Configures onOpenChange for this component. |
showArrow | boolean | No | Inherited showArrow attribute accepted by DropdownMenu. |
DropdownMenuTriggerProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by DropdownMenu. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by DropdownMenu. |
id | string | No | Inherited id attribute accepted by DropdownMenu. |
role | string | No | Inherited role attribute accepted by DropdownMenu. |
style | Record<string, unknown> | No | Inherited style attribute accepted by DropdownMenu. |
title | string | No | Inherited title attribute accepted by DropdownMenu. |
tabIndex | number | No | Inherited tabIndex attribute accepted by DropdownMenu. |
hidden | boolean | No | Inherited hidden attribute accepted by DropdownMenu. |
disabled | boolean | No | Inherited disabled attribute accepted by DropdownMenu. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by DropdownMenu. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by DropdownMenu. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by DropdownMenu. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by DropdownMenu. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by DropdownMenu. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by DropdownMenu. |
label | string | No | Inherited label attribute accepted by DropdownMenu. |
DropdownMenuContentProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by DropdownMenu. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by DropdownMenu. |
id | string | No | Inherited id attribute accepted by DropdownMenu. |
role | string | No | Inherited role attribute accepted by DropdownMenu. |
style | Record<string, unknown> | No | Inherited style attribute accepted by DropdownMenu. |
title | string | No | Inherited title attribute accepted by DropdownMenu. |
tabIndex | number | No | Inherited tabIndex attribute accepted by DropdownMenu. |
hidden | boolean | No | Inherited hidden attribute accepted by DropdownMenu. |
disabled | boolean | No | Inherited disabled attribute accepted by DropdownMenu. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by DropdownMenu. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by DropdownMenu. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by DropdownMenu. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by DropdownMenu. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by DropdownMenu. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by DropdownMenu. |
use | ElementDirectiveInput<HTMLDivElement> | No | Inherited use attribute accepted by DropdownMenu. |
DropdownMenuItemProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by DropdownMenu. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by DropdownMenu. |
id | string | No | Inherited id attribute accepted by DropdownMenu. |
role | string | No | Inherited role attribute accepted by DropdownMenu. |
style | Record<string, unknown> | No | Inherited style attribute accepted by DropdownMenu. |
title | string | No | Inherited title attribute accepted by DropdownMenu. |
tabIndex | number | No | Inherited tabIndex attribute accepted by DropdownMenu. |
hidden | boolean | No | Inherited hidden attribute accepted by DropdownMenu. |
disabled | boolean | No | Inherited disabled attribute accepted by DropdownMenu. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by DropdownMenu. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by DropdownMenu. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by DropdownMenu. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by DropdownMenu. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by DropdownMenu. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by DropdownMenu. |
href | string | No | Inherited href attribute accepted by DropdownMenu. |
closeOnSelect | boolean | No | Inherited closeOnSelect attribute accepted by DropdownMenu. |
onSelect | (event: MouseEvent) => void | No | Inherited onSelect attribute accepted by DropdownMenu. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | Use defaultOpen for browser-owned disclosure state, or open with onOpenChange and update application state after each request. |
| DOM target | Public passthrough props target the component root. Treat nested elements and private class names as implementation details. |
Anatomy and related components
Limitations
Use Popover when the floating surface contains arbitrary content, fields, filters, or explanations rather than a command list.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Content uses `role="menu"` and items use `role="menuitem"`.
Content uses `role="menu"` and items use `role="menuitem"`.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | feedback |
| Component import | @tavojs/ui/dropdown-menu |
| Explicit CSS import | @tavojs/ui/css/dropdown-menu |
| Preview | Interactive preview available on this page |