--- title: Menu description: "`Menu` is a component that displays a common dropdown menu." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/menu/menu.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/menu - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-menu--basic --- ```tsx うずまきナルト うちはサスケ 春野サクラ ``` ## Usage ```tsx import { Menu } from "@yamada-ui/react" ``` ```tsx import { Menu } from "@/components/ui" ``` ```tsx import { Menu } from "@workspaces/ui" ``` ```tsx ``` ### Use Items ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( ) ``` ### Change Size ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( {(size) => ( )} ) ``` ### Handle Selection Event To handle selection event, use `onSelect`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( console.log("selected", value)}> ) ``` ### Add Dividers ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, { type: "separator" }, { label: "大蛇丸", value: "orochimaru" }, { label: "自來也", value: "pervy-sage" }, { label: "綱手", value: "tsunade" }, ], [], ) return ( うずまきナルト うちはサスケ 春野サクラ 大蛇丸 自來也 綱手 ) ``` ### Grouping ```tsx const items = useMemo( () => [ { items: [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], label: "第七班", }, { items: [ { label: "大蛇丸", value: "orochimaru" }, { label: "自來也", value: "pervy-sage" }, { label: "綱手", value: "tsunade" }, ], label: "伝説の三忍", }, ], [], ) return ( うずまきナルト うちはサスケ 春野サクラ 大蛇丸 自來也 綱手 ) ``` ### Display Icons ```tsx const items = useMemo( () => [ { label: ( <> New Tab ), value: "tab", }, { label: ( <> New Window ), value: "window", }, { label: ( <> New File ), value: "file", }, ], [], ) return ( New Tab New Window New File ) ``` ### Display Commands ```tsx const items = useMemo( () => [ { label: ( <> New Tab ⌘T ), value: "tab", }, { label: ( <> New Window ⌘N ), value: "window", }, { label: ( <> Open File ⌘O ), value: "file", }, ], [], ) return ( New Tab ⌘T New Window ⌘N Open File ⌘O ) ``` ### Set Selectable Items ```tsx const [value, setValue] = useState("naruto") const items = useMemo( () => [ { type: "checkbox", items: [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, { label: "はたけカカシ", value: "kakashi", disabled: true }, ], value, onChange: setValue, }, ], [value], ) return ( うずまきナルト うちはサスケ 春野サクラ はたけカカシ ) ``` ### Nested Menu ```tsx うずまきナルト うちはサスケ 春野サクラ Settings Extensions Theme User Tasks ``` ### Use Context Menu ```tsx
Right Click Here
Copy Paste Delete
``` ### Display Menu on Different Element ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return (
Here display Popover
) ``` ### Disable Close on Select To disable the close on select, set `closeOnSelect` to `false`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( ) ``` ### Set Initial Focus To set initial focus, pass a `Ref` to `initialFocusRef`. ```tsx const ref = useRef(null) return ( Set Status Edit Profile Preferences ) ``` ### Change Placement To change the display position, set `placement` to `"start"`, `"end-end"`, etc. By default, `"end-start"` is set. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( {(placement) => ( )} ) ``` ### Change Animation To change the animation, set `animationScheme` to `"inline-start"`, `"block-end"`, etc. By default, `"scale"` is set. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( {(animationScheme) => ( )} ) ``` ### Change Offset To change the offset, set a value to `gutter` or `offset`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( ) ``` ### Change Duration To change the duration, set a numerical value (seconds) to `duration`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( ) ``` ### Access Internal State To access internal state, pass a function to the `children` of `Menu.Root`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( {({ open }) => ( <> )} ) ``` ### Disable Close on Outside Click To disable closing when clicking outside, set `closeOnBlur` to `false`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( ) ``` ### Disabling Items To disable items, set `disabled` to `true`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke", disabled: true }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( ) ``` ### Add Header or Footer To add header or footer, set `ReactNode` to `header` or `footer` of `Menu.Content`. ```tsx const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, { label: "大蛇丸", value: "orochimaru" }, { label: "自來也", value: "pervy-sage" }, { label: "綱手", value: "tsunade" }, ], [], ) return ( ) ``` ### Control ```tsx const { open, onOpen, onClose } = useDisclosure() const items = useMemo( () => [ { label: "うずまきナルト", value: "naruto" }, { label: "うちはサスケ", value: "sasuke" }, { label: "春野サクラ", value: "sakura" }, ], [], ) return ( ) ``` ## Props ### Menu.Root | Prop | Default | Type | Description | | ---------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `size` | `"md"` | `"lg" \| "md" \| "sm"` | The size of the component. | | `animationScheme` | `"scale"` | `"scale" \| "none" \| SimplePlacement` | The animation of the element. | | `autoUpdate` | `true` | `boolean` | If `true`, automatically updates the position of the floating element when necessary. | | `blockScrollOnMount` | `false` | `boolean` | If `true`, scrolling will be disabled on the `body` when the modal opens. | | `children` | - | `string \| number \| bigint \| boolean \| ReactElement> \| Iterable \| ReactPortal \| Promise<...> \| ((props: { ...; }) => ReactNode)` | The children of the popover. | | `closeOnBlur` | `true` | `boolean` | If `true`, the popover will close when you blur out it by clicking outside or tabbing out. | | `closeOnEsc` | `true` | `boolean` | If `true`, the popover will hide on pressing Esc key. | | `closeOnScroll` | `false` | `boolean` | If `true`, the popover will hide on scroll. | | `closeOnSelect` | `true` | `boolean` | If `true`, the menu item will be closed when selected. | | `defaultOpen` | - | `boolean` | If `true`, the element will be initially opened. | | `disabled` | `false` | `boolean` | If `true`, the menu will be disabled. | | `duration` | `0.2` | `number \| MotionLifecycleProps` | The animation duration. | | `elements` | - | `{ floating?: HTMLElement \| null \| undefined; reference?: HTMLButtonElement \| null \| undefined }` | Object containing the reference and floating elements. | | `flip` | `true` | `boolean` | If `true`, the popper will change its placement and flip when it's about to overflow its boundary area. | | `gutter` | `8` | `number` | The distance or margin between the reference and popper. It is used internally to create an `offset` modifier. | | `initialFocusRef` | - | `RefObject` | The `ref` of the element that should receive focus when the popover opens. | | `matchWidth` | `false` | `boolean` | If `true`, the popper will match the width of the reference at all times. It's useful for `autocomplete`, `date-picker` and `select` patterns. | | `middleware` | - | `(false \| { name: string; options?: any; fn: (state: { x: number; y: number; placement: Placement; platform: Platform; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; elements: Elements; }) => Promisable<...>; } \| null \| undefined)[]` | Array of middleware objects to modify the positioning or provide data for rendering. | | `offset` | - | `[number, number]` | The main and cross-axis offset to displace popper element from its reference element. | | `onClose` | - | `() => void \| Promise` | Callback invoked to close the element. | | `onOpen` | - | `() => void \| Promise` | Callback invoked to open the element. | | `onSelect` | - | `(value?: string) => void` | Callback invoked when a menu item is selected. | | `open` | - | `boolean` | If `true`, the element will be opened. | | `openOnClick` | `true` | `boolean` | If `true`, the popover will be opened when click on the field. | | `placement` | `"end-start"` | `Direction` | The placement of the popper relative to its reference. | | `platform` | - | `Platform` | Custom or extended platform object. | | `preventOverflow` | `true` | `boolean` | If `true`, will prevent the popper from being cut off and ensure it's visible within the boundary area. | | `strategy` | `"absolute"` | `Strategy` | The CSS positioning strategy to use. | | `subMenuDirection` | `"end"` | `SubMenuDirection` | The direction of the sub menu. | | `transferFocus` | `true` | `boolean` | If `true`, the focus will be transferred to the popover content when the tab key is pressed. | | `transform` | `true` | `boolean` | Whether to use `transform` for positioning instead of `top` and `left` (layout) in the `floatingStyles` object. | | `whileElementsMounted` | - | `(reference: HTMLButtonElement, floating: HTMLElement, update: () => void) => () => void` | A callback invoked when both the reference and floating elements are mounted, and cleaned up when either is unmounted. This is useful for setting up event listeners (e.g. pass `autoUpdate`). | ### Menu.Anchor | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Menu.Command | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Menu.Content | Prop | Default | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | | `as` | - | `keyof IntrinsicElements` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `footer` | - | `ReactNode` | The footer of the menu. | | `footerProps` | - | `MenuFooterProps` | Props for the footer component. | | `header` | - | `ReactNode` | The header of the menu. | | `headerProps` | - | `MenuHeaderProps` | Props for the header component. | | `items` | - | `(MenuItemWithCheckboxGroup \| MenuItemWithItems \| MenuItemWithRadioGroup \| MenuItemWithSeparator \| MenuItemWithValue)[]` | If provided, generate elements based on items. | | `portalProps` | - | `Omit` | Props for portal component. | ### Menu.Footer | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Menu.Group | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `label` | - | `ReactNode` | The label of the group. | | `labelProps` | - | `MenuLabelProps` | Props for the label component. | ### Menu.Header | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Menu.Indicator | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Menu.Item | Prop | Default | Type | Description | | --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `closeOnSelect` | - | `boolean` | If `true`, the menu item will be closed when selected. | | `disabled` | `false` | `boolean` | If `true`, the menu item will be disabled. | | `value` | - | `string` | The value of the menu item. | ### Menu.Label | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Menu.OptionGroup | Prop | Default | Type | Description | | -------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `defaultValue` | - | `M` | The initial value of the menu item group. | | `label` | - | `string \| number \| bigint \| boolean \| ReactElement> \| Iterable \| ReactPortal \| Promise<...>` | The label of the group. | | `labelProps` | - | `MenuLabelProps` | Props for the label component. | | `onChange` | - | `(value: M) => void` | The callback fired when any children checkbox is checked or unchecked. | | `type` | - | `Y` | The type of the menu option group. | | `value` | - | `M` | The value of the menu item group. | ### Menu.OptionItem | Prop | Default | Type | Description | | --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `value` | - | `string` | The value of the menu option item. | | `closeOnSelect` | - | `boolean` | If `true`, the menu item will be closed when selected. | | `disabled` | `false` | `boolean` | If `true`, the menu item will be disabled. | | `icon` | - | `ReactNode` | The icon to be used in the menu option item. | ### Menu.Separator | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Menu.Trigger | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ## Accessibility Currently, this section is being updated due to the migration of v2.