Menu
Contextual actions anchored to an icon button.
Installation
pnpm dlx shadcn@latest add https://react-toolbox.io/r/menu.jsonNew here? Set up your project first. Styles, fonts, and required components are included.
Usage
IconMenu handles opening, keyboard navigation, and dismissal. Use onSelect to respond to an item value. Menu and MenuDivider are also available for custom compositions.
Use the Code tab above for a complete example. The import follows your configured UI alias. See Theming to customize colors, spacing, and style slots.
State and callbacks
Menu visibility and selected value are controlled through active and selected. Update selected from onSelect; use onHide to close a controlled popup. Selection and visibility are separate.
IconMenu manages trigger opening and dismissal internally and synchronizes changes to active. Its selected value remains controlled. The ref exposes open(), close(), and node for imperative integration.
API reference
Generated from the installed TypeScript source. Defaults are the values declared by each function; a dash means no parameter default is declared. Forwarded props can use the receiving component’s default. Callback types show the exact arguments passed to your handler.
Menu
| Property | Type | Default |
|---|---|---|
active | boolean | false |
initialFocus | 'first' | 'last' | 'first' |
outline | boolean | true |
position | MenuPosition | 'static' |
ripple | boolean | true |
selectable | boolean | true |
selected | Value | — |
classNames | MenuThemeClasses for the component's rendered parts. Applied after legacy theme overrides. | — |
themeDeprecated alias | MenuThemeUse classNames for style slots; use ThemeProvider for design tokens. | — |
ref | Ref<MenuHandle> | — |
Callbacks
| Property | Type | Default |
|---|---|---|
onHide | () => void | — |
onSelect | (value: Value | undefined) => void | — |
onShow | () => void | — |
onKeyDown | (event: KeyboardEvent<HTMLUListElement>) => void | — |
Also inherits Omit<HTMLAttributes<HTMLDivElement>, 'onSelect' | 'onKeyDown'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.
Style slots
Pass a map of Tailwind classes to classNames. Available keys:
activebottomLeftbottomRightcaptiondisablediconiconMenumenumenuDividermenuInnermenuItemoutlineripplerippledselectedshortcutstatictopLefttopRight
theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.
MenuItem
| Property | Type | Default |
|---|---|---|
caption | ReactNode | — |
disabled | boolean | false |
icon | ReactNode | — |
selected | boolean | false |
shortcut | ReactNode | — |
value | Value | — |
ripple | boolean | true |
classNames | MenuItemThemeClasses for the component's rendered parts. Applied after legacy theme overrides. | — |
themeDeprecated alias | MenuItemThemeUse classNames for style slots; use ThemeProvider for design tokens. | — |
ref | Ref<MenuItemHandle<Value>> | — |
Callbacks
| Property | Type | Default |
|---|---|---|
onClick | (event: MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>, item: MenuItemHandle<Value>) => void | — |
Also inherits Omit<HTMLAttributes<HTMLLIElement>, 'onClick'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.
Style slots
Pass a map of Tailwind classes to classNames. Available keys:
activebottomLeftbottomRightcaptiondisablediconiconMenumenumenuDividermenuInnermenuItemoutlineripplerippledselectedshortcutstatictopLefttopRight
theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.
MenuDivider
| Property | Type | Default |
|---|---|---|
classNames | MenuDividerThemeClasses for the component's rendered parts. Applied after legacy theme overrides. | — |
themeDeprecated alias | MenuDividerThemeUse classNames for style slots; use ThemeProvider for design tokens. | — |
ref | Ref<HTMLHRElement> | — |
Also inherits HTMLAttributes<HTMLHRElement>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.
Style slots
Pass a map of Tailwind classes to classNames. Available keys:
activebottomLeftbottomRightcaptiondisablediconiconMenumenumenuDividermenuInnermenuItemoutlineripplerippledselectedshortcutstatictopLefttopRight
theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.
IconMenu
| Property | Type | Default |
|---|---|---|
active | boolean | false |
icon | ReactNode | 'more_vert' |
iconRipple | boolean | true |
inverse | boolean | — |
menuRipple | boolean | true |
position | MenuPosition | 'auto' |
selectable | boolean | false |
selected | Value | — |
classNames | IconMenuThemeClasses for the component's rendered parts. Applied after legacy theme overrides. | — |
themeDeprecated alias | IconMenuThemeUse classNames for style slots; use ThemeProvider for design tokens. | — |
ref | Ref<IconMenuHandle> | — |
Callbacks
| Property | Type | Default |
|---|---|---|
onClick | React.MouseEventHandler<HTMLElement> | — |
onHide | () => void | — |
onSelect | (value: Value | undefined) => void | — |
onShow | () => void | — |
Also inherits Omit<HTMLAttributes<HTMLDivElement>, 'onSelect' | 'onClick'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.
Style slots
Pass a map of Tailwind classes to classNames. Available keys:
activebottomLeftbottomRightcaptiondisablediconiconMenumenumenuDividermenuInnermenuItemoutlineripplerippledselectedshortcutstatictopLefttopRight
theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.
Exported TypeScript types
Expand a type to inspect its full declaration, including generic constraints, union branches, callback arguments, ref handles, and inherited props. Import these types from @/components/ui/material/menu.
MenuTheme
type MenuTheme = Partial<
Record<
| 'active'
| 'bottomLeft'
| 'bottomRight'
| 'caption'
| 'disabled'
| 'icon'
| 'iconMenu'
| 'menu'
| 'menuDivider'
| 'menuInner'
| 'menuItem'
| 'outline'
| 'ripple'
| 'rippled'
| 'selected'
| 'shortcut'
| 'static'
| 'topLeft'
| 'topRight',
string
>
>;MenuClassNames
type MenuClassNames = MenuTheme;MenuPosition
type MenuPosition = 'auto' | 'static' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';MenuHandle
interface MenuHandle {
show(): void;
hide(): void;
readonly node: HTMLDivElement | null;
}MenuProps
interface MenuProps<Value = unknown> extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect' | 'onKeyDown'> {
active?: boolean;
initialFocus?: 'first' | 'last';
onHide?: () => void;
onSelect?: (value: Value | undefined) => void;
onShow?: () => void;
onKeyDown?: (event: KeyboardEvent<HTMLUListElement>) => void;
outline?: boolean;
position?: MenuPosition;
ripple?: boolean;
selectable?: boolean;
selected?: Value;
/** Classes for the component's rendered parts. Applied after legacy theme overrides. */
classNames?: MenuTheme;
/** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
theme?: MenuTheme;
ref?: Ref<MenuHandle>;
}MenuItemTheme
type MenuItemTheme = MenuTheme;MenuItemEvent
type MenuItemEvent = MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>;MenuItemHandle
interface MenuItemHandle<Value = unknown> {
readonly node: HTMLLIElement | null;
readonly value: Value | undefined;
}MenuItemProps
interface MenuItemProps<Value = unknown> extends Omit<HTMLAttributes<HTMLLIElement>, 'onClick'> {
caption?: ReactNode;
disabled?: boolean;
icon?: ReactNode;
selected?: boolean;
shortcut?: ReactNode;
value?: Value;
ripple?: boolean;
onClick?: (event: MenuItemEvent, item: MenuItemHandle<Value>) => void;
/** Classes for the component's rendered parts. Applied after legacy theme overrides. */
classNames?: MenuItemTheme;
/** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
theme?: MenuItemTheme;
ref?: Ref<MenuItemHandle<Value>>;
}MenuItemClassNames
type MenuItemClassNames = MenuItemTheme;MenuDividerTheme
type MenuDividerTheme = MenuTheme;MenuDividerProps
interface MenuDividerProps extends HTMLAttributes<HTMLHRElement> {
/** Classes for the component's rendered parts. Applied after legacy theme overrides. */
classNames?: MenuDividerTheme;
/** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
theme?: MenuDividerTheme;
ref?: Ref<HTMLHRElement>;
}MenuDividerClassNames
type MenuDividerClassNames = MenuDividerTheme;IconMenuTheme
type IconMenuTheme = MenuTheme;IconMenuHandle
interface IconMenuHandle {
open(): void;
close(): void;
readonly node: HTMLDivElement | null;
}IconMenuProps
interface IconMenuProps<Value = unknown> extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect' | 'onClick'> {
active?: boolean;
icon?: ReactNode;
iconRipple?: boolean;
inverse?: boolean;
menuRipple?: boolean;
onClick?: React.MouseEventHandler<HTMLElement>;
onHide?: () => void;
onSelect?: MenuProps<Value>['onSelect'];
onShow?: () => void;
position?: MenuPosition;
selectable?: boolean;
selected?: Value;
/** Classes for the component's rendered parts. Applied after legacy theme overrides. */
classNames?: IconMenuTheme;
/** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
theme?: IconMenuTheme;
ref?: Ref<IconMenuHandle>;
}IconMenuClassNames
type IconMenuClassNames = IconMenuTheme;Material guidelines
- Menus present brief contextual choices near their trigger. Use a navigation drawer or other persistent navigation pattern for top-level destinations.
- Use short, single-line labels and dismiss the menu after a single selection. If choices need wrapping or extensive explanation, use a dialog.