# Menubar
Package: @mantine/core
Import: import { Menubar } from '@mantine/core';
Description: Desktop application style menubar with a row of menu triggers

## Usage

`Menubar` is a horizontal row of menu triggers (File, Edit, View), each opening a dropdown.
It is built on top of [Menu](https://alpha.mantine.dev/llms/core-menu.md): dropdown content is composed from `Menu.Item`,
`Menu.Divider` and other `Menu` components:

```tsx
import { Menu, Menubar, Text } from '@mantine/core';

function Demo() {
  return (
    <Menubar aria-label="Application menu">
      <Menubar.Menu width={220}>
        <Menubar.Target>File</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item rightSection={<Text size="xs">⌘N</Text>}>New file</Menu.Item>
          <Menu.Item rightSection={<Text size="xs">⌘⇧N</Text>}>New window</Menu.Item>
          <Menu.Sub>
            <Menu.Sub.Target>
              <Menu.Sub.Item>Open recent</Menu.Sub.Item>
            </Menu.Sub.Target>
            <Menu.Sub.Dropdown>
              <Menu.Item>project-alpha</Menu.Item>
              <Menu.Item>project-beta</Menu.Item>
              <Menu.Item>project-gamma</Menu.Item>
            </Menu.Sub.Dropdown>
          </Menu.Sub>
          <Menu.Divider />
          <Menu.Item rightSection={<Text size="xs">⌘S</Text>}>Save</Menu.Item>
          <Menu.Item>Save as…</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>

      <Menubar.Menu width={220}>
        <Menubar.Target>Edit</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item rightSection={<Text size="xs">⌘Z</Text>}>Undo</Menu.Item>
          <Menu.Item rightSection={<Text size="xs">⌘⇧Z</Text>}>Redo</Menu.Item>
          <Menu.Divider />
          <Menu.Item>Cut</Menu.Item>
          <Menu.Item>Copy</Menu.Item>
          <Menu.Item>Paste</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>

      <Menubar.Menu width={220}>
        <Menubar.Target>Help</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item>Documentation</Menu.Item>
          <Menu.Item>Keyboard shortcuts</Menu.Item>
          <Menu.Item>About</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>
    </Menubar>
  );
}
```


## How it differs from Menu

`Menu` is one target that toggles one dropdown. `Menubar` coordinates multiple menus:

* Only one menu is open at a time, moving to another target switches the open menu
* The whole bar is a single tab stop, arrow keys move focus between targets

If you need a single dropdown attached to one button, use [Menu](https://alpha.mantine.dev/llms/core-menu.md) instead.

## Composition

* `Menubar` – root element
* `Menubar.Menu` – wraps a single menu, accepts the same props as `Menu`
* `Menubar.Target` – top-level trigger button
* `Menubar.Dropdown` – dropdown container, accepts the same children as `Menu.Dropdown`

```tsx
import { Menu, Menubar } from '@mantine/core';

function Demo() {
  return (
    <Menubar>
      <Menubar.Menu>
        <Menubar.Target>File</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item>New file</Menu.Item>
          <Menu.Item>Open…</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>

      <Menubar.Menu>
        <Menubar.Target>Edit</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item>Undo</Menu.Item>
          <Menu.Item>Redo</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>
    </Menubar>
  );
}
```

## Trigger and loop

By default, a menu opens on click, and hovering another target switches the open menu.
Set `trigger="hover"` to open menus on hover. Set `loop={false}` to stop arrow key
navigation from wrapping around:

```tsx
import { Menu, Menubar } from '@mantine/core';

function Demo() {
  return (
    <Menubar aria-label="Application menu" trigger="hover">
      <Menubar.Menu width={220}>
        <Menubar.Target>File</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item>New file</Menu.Item>
          <Menu.Item>New window</Menu.Item>
          <Menu.Item>Save</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>

      <Menubar.Menu width={220}>
        <Menubar.Target>Edit</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item>Undo</Menu.Item>
          <Menu.Item>Redo</Menu.Item>
          <Menu.Item>Cut</Menu.Item>
          <Menu.Item>Copy</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>

      <Menubar.Menu width={220}>
        <Menubar.Target>View</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item>Zoom in</Menu.Item>
          <Menu.Item>Zoom out</Menu.Item>
          <Menu.Item>Reset zoom</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>
    </Menubar>
  );
}
```


## Submenus

Use `Menu.Sub` inside `Menubar.Dropdown` to create nested submenus, see
[Menu submenus](https://alpha.mantine.dev/llms/core-menu.md#submenus). The usage demo above has a submenu in the File menu.

## Checkbox and radio items

Use `Menu.CheckboxItem` for toggles and `Menu.RadioGroup` with `Menu.RadioItem` for
single-choice options. Clicking these items does not close the menu:

```tsx
import { Menu, Menubar } from '@mantine/core';

function Demo() {
  return (
    <Menubar aria-label="Application menu">
      <Menubar.Menu width={220}>
        <Menubar.Target>View</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.CheckboxItem defaultChecked>Show sidebar</Menu.CheckboxItem>
          <Menu.CheckboxItem>Show status bar</Menu.CheckboxItem>
          <Menu.Divider />
          <Menu.Label>Appearance</Menu.Label>
          <Menu.RadioGroup defaultValue="comfortable">
            <Menu.RadioItem value="compact">Compact</Menu.RadioItem>
            <Menu.RadioItem value="comfortable">Comfortable</Menu.RadioItem>
            <Menu.RadioItem value="spacious">Spacious</Menu.RadioItem>
          </Menu.RadioGroup>
        </Menubar.Dropdown>
      </Menubar.Menu>

      <Menubar.Menu width={220}>
        <Menubar.Target>Window</Menubar.Target>
        <Menubar.Dropdown>
          <Menu.Item>Minimize</Menu.Item>
          <Menu.Item>Zoom</Menu.Item>
          <Menu.Item>Bring all to front</Menu.Item>
        </Menubar.Dropdown>
      </Menubar.Menu>
    </Menubar>
  );
}
```


## Controlled

Use `openIndex` and `onOpenChange` props to control which menu is open. `openIndex` is the
index of the opened `Menubar.Menu` or `null` when all menus are closed. Use `defaultOpenIndex`
to open a menu initially without controlling the state:

```tsx
import { useState } from 'react';
import { Button, Group, Menu, Menubar, Stack } from '@mantine/core';

function Demo() {
  const [openIndex, setOpenIndex] = useState<number | null>(null);

  return (
    <Stack>
      <Group>
        <Button variant="default" onClick={() => setOpenIndex(0)}>Open File</Button>
        <Button variant="default" onClick={() => setOpenIndex(1)}>Open Edit</Button>
        <Button variant="default" onClick={() => setOpenIndex(null)}>Close all</Button>
      </Group>

      <Menubar aria-label="Application menu" openIndex={openIndex} onOpenChange={setOpenIndex}>
        <Menubar.Menu width={220}>
          <Menubar.Target>File</Menubar.Target>
          <Menubar.Dropdown>
            <Menu.Item>New file</Menu.Item>
            <Menu.Item>Save</Menu.Item>
          </Menubar.Dropdown>
        </Menubar.Menu>

        <Menubar.Menu width={220}>
          <Menubar.Target>Edit</Menubar.Target>
          <Menubar.Dropdown>
            <Menu.Item>Undo</Menu.Item>
            <Menu.Item>Redo</Menu.Item>
          </Menubar.Dropdown>
        </Menubar.Menu>
      </Menubar>
    </Stack>
  );
}
```


## Controlling with useMenubar

`Menubar` supports the [controller pattern](https://alpha.mantine.dev/llms/guides-controllers.md). Use the `useMenubar` hook
to manage `Menubar` state. When `controller` is set, the open index and `loop` props of
`Menubar` are ignored, pass them to `useMenubar` instead:

```tsx
import { Button, Code, Group, Menu, Menubar, Stack, Text, useMenubar } from '@mantine/core';
import { useWindowEvent } from '@mantine/hooks';

function Demo() {
  const controller = useMenubar();

  // Alt + F opens the File menu and moves focus into it,
  // which the openIndex prop alone cannot do
  useWindowEvent('keydown', (event) => {
    if (event.altKey && event.code === 'KeyF') {
      event.preventDefault();
      controller.openMenu(0);
      controller.focusMenuItem(0, 'first');
    }
  });

  return (
    <Stack>
      <Menubar aria-label="Application menu" controller={controller}>
        <Menubar.Menu width={220}>
          <Menubar.Target>File</Menubar.Target>
          <Menubar.Dropdown>
            <Menu.Item>New file</Menu.Item>
            <Menu.Item>Save</Menu.Item>
          </Menubar.Dropdown>
        </Menubar.Menu>

        <Menubar.Menu width={220}>
          <Menubar.Target>Edit</Menubar.Target>
          <Menubar.Dropdown>
            <Menu.Item>Undo</Menu.Item>
            <Menu.Item>Redo</Menu.Item>
          </Menubar.Dropdown>
        </Menubar.Menu>

        <Menubar.Menu width={220}>
          <Menubar.Target>View</Menubar.Target>
          <Menubar.Dropdown>
            <Menu.Item>Zoom in</Menu.Item>
            <Menu.Item>Zoom out</Menu.Item>
          </Menubar.Dropdown>
        </Menubar.Menu>
      </Menubar>

      <Group>
        <Button variant="default" onClick={() => controller.focusPreviousMenu()}>
          Focus previous
        </Button>
        <Button variant="default" onClick={() => controller.focusNextMenu()}>
          Focus next
        </Button>
        <Button
          variant="default"
          onClick={() => {
            controller.openMenu(controller.getActiveIndex());
            controller.focusMenuItem(controller.getActiveIndex(), 'first');
          }}
        >
          Open focused menu
        </Button>
        <Button variant="default" onClick={controller.closeMenu}>
          Close
        </Button>
      </Group>

      <Text size="sm">
        Opened: <Code>{String(controller.getOpenIndex())}</Code>, focused:{' '}
        <Code>{controller.getActiveIndex()}</Code>, menus: <Code>{controller.getMenuCount()}</Code>. Press{' '}
        <Code>Alt + F</Code> to open the File menu from anywhere.
      </Text>
    </Stack>
  );
}
```


`useMenubar` returns the current state, actions and queries:

```tsx
import { Menubar, useMenubar } from '@mantine/core';

function Demo() {
  const controller = useMenubar({
    defaultOpenIndex: 0, // -> uncontrolled initial value
    loop: false, // -> same as the loop prop of Menubar
    // openIndex, onOpenChange -> controlled state, same as on Menubar
  });

  // Actions
  controller.openMenu(1); // -> opens the menu and moves the tab stop to it
  controller.openMenu(1, 'hover'); // -> same, recorded as opened by hover
  controller.closeMenu();
  controller.toggleMenu(1);
  controller.setOpenIndex(1); // -> sets the index directly, null closes all menus

  // Focus actions
  controller.focusMenu(1); // -> focuses the target, switches the open menu if one is open
  controller.focusNextMenu(); // -> next enabled menu, respects loop
  controller.focusPreviousMenu();
  controller.focusFirstMenu();
  controller.focusLastMenu();
  controller.focusMenuItem(1, 'first'); // -> focuses the first item of the opened menu, call after openMenu

  // Queries
  controller.getOpenIndex(); // -> index of the opened menu, null when all menus are closed
  controller.getActiveIndex(); // -> index of the menu that holds the menubar tab stop
  controller.isMenuOpen(1); // -> boolean
  controller.getMenuCount(); // -> number of Menubar.Menu components rendered by Menubar
  controller.getEnabledIndexes(); // -> indexes of the menus that are not disabled
  controller.getOpenSource(); // -> 'click' | 'hover' | null

  return <Menubar controller={controller}>{/* menus */}</Menubar>;
}
```

## Position

Set the `position` prop to change the [dropdown position](https://alpha.mantine.dev/llms/core-menu.md#dropdown-position)
of all menus in the bar:

```tsx
import { Menubar } from '@mantine/core';

function Demo() {
  return (
    <Menubar position="bottom-end">
      {/* ...menus */}
    </Menubar>
  );
}
```

To override settings of a single menu, pass `Menu` props to `Menubar.Menu`,
for example `position` or `closeOnItemClick`.

## Accessibility

Set `aria-label` on `Menubar` to give the bar an accessible name:

```tsx
import { Menubar } from '@mantine/core';

function Demo() {
  return <Menubar aria-label="Application menu">{/* ...menus */}</Menubar>;
}
```


#### Props

**Menubar props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| children | React.ReactNode | - | `Menubar.Menu` components |
| controller | MenubarController | - | Controller returned by the `useMenubar` hook. When provided, the state is owned by the controller and `openIndex`, `defaultOpenIndex`, `onOpenChange` and `loop` props are ignored |
| defaultOpenIndex | number \| null | `null` | Index of the opened menu for uncontrolled component |
| loop | boolean | `true` | If set, arrow key navigation wraps from last to first menu and vice versa |
| onOpenChange | (index: number \| null) => void | - | Called when the opened menu changes with its index or `null` when all menus are closed |
| openIndex | number \| null | - | Index of the controlled opened menu, `null` closes all menus |
| position | FloatingPosition | `'bottom-start'` | Dropdown position relative to the target element |
| trigger | "hover" \| "click" | `'click'` | Event that opens a menu when none of the menus is opened. `'click'` opens a menu on target click and then switches menus on hover (desktop application pattern), `'hover'` opens a menu when the target is hovered |

**Menubar.Menu props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| alignItemsLabels | "none" \| "all" \| "with-indicators" | 'with-indicators' | Controls how indicator slot space is reserved on menu items for label alignment. `'all'` reserves space on every `Menu.Item`, `'with-indicators'` reserves space only on `Menu.CheckboxItem` and `Menu.RadioItem`, `'none'` reserves space only on items that currently display an indicator. |
| arrowOffset | number | 5 | Arrow offset in px |
| arrowPosition | 'center' \| 'side' | - | Arrow position |
| arrowRadius | number | 0 | Arrow `border-radius` in px |
| arrowSize | number | 7 | Arrow size in px |
| checkIcon | React.ReactNode | - | Custom icon rendered as the indicator of checked `Menu.CheckboxItem` and selected `Menu.RadioItem`. Can be overridden per item with the `checkIcon` prop. |
| children | React.ReactNode | - | `Menubar.Target` and `Menubar.Dropdown` components |
| clickOutsideCapture | boolean | false | If set, outside click listeners are registered in the capture phase |
| clickOutsideEvents | string[] | ['mousedown', 'touchstart', 'keydown'] | Events that trigger outside click detection. Includes mousedown for desktop clicks, touchstart for mobile, and keydown for Escape key handling |
| closeDelay | number | - | Close delay in ms, applicable only to `trigger="hover"` variant |
| closeOnClickOutside | boolean | - | If set, the dropdown is closed on outside clicks |
| closeOnEscape | boolean | true | If set, the dropdown is closed when the `Escape` key is pressed |
| closeOnItemClick | boolean | - | If set, the Menu is closed when one of the items is clicked. Can be overridden per item with `closeMenuOnClick` prop |
| disabled | boolean | - | If set, popover dropdown will not be rendered |
| dismissMode | "tree" \| "legacy" | 'tree' | `'tree'` treats nested portaled dropdowns as inside and dismisses the innermost popover on Escape. `'legacy'` uses DOM containment and dropdown capture-phase Escape handling. |
| escapeKeyBubbles | boolean | false | In tree mode, lets Escape dismiss ancestor popovers as well as this dropdown. |
| floatingStrategy | FloatingStrategy | 'absolute' | Changes floating ui [position strategy](https://floating-ui.com/docs/usefloating#strategy) |
| hideDetached | boolean | true | If set, the dropdown is hidden when the element is hidden with styles or not visible on the screen |
| id | string | - | Id base to create accessibility connections |
| keepMounted | boolean | - | If set, the dropdown is not unmounted from the DOM when hidden. `display: none` styles are added instead. |
| keepMountedMode | "activity" \| "display-none" | 'activity' | Controls how the dropdown is hidden when `keepMounted` is set: `'activity'` – hidden with React 19 `Activity` component, `'display-none'` – hidden with `display: none` styles |
| loop | boolean | - | If set, arrow key presses wrap around from last item to first and vice versa |
| menuItemTabIndex | 0 \| -1 | -1 | Set the `tabindex` on all menu items. Use `0` to allow Tab key navigation through menu items (required for navigation menus following WAI-ARIA disclosure pattern). |
| middlewares | PopoverMiddlewares | { flip: true, shift: true, inline: false } | Floating ui middlewares to configure position handling |
| offset | number \| FloatingAxesOffsets | 8 | Offset of the dropdown element |
| onDismiss | (reason: "escape-key" \| "outside-press") => void | - | Called when the popover is dismissed by clicking outside or by pressing escape |
| onEnterTransitionEnd | () => void | - | Called when enter transition ends |
| onExitTransitionEnd | () => void | - | Called when exit transition ends |
| onPositionChange | (position: FloatingPosition) => void | - | Called when dropdown position changes |
| openDelay | number | - | Open delay in ms, applicable only to `trigger="hover"` variant |
| overlayProps | OverlayProps & ElementProps<"div"> | - | Props passed down to `Overlay` component |
| portalProps | BasePortalProps | - | Props to pass down to the `Portal` when `withinPortal` is true |
| position | FloatingPosition | 'bottom' | Dropdown position relative to the target element |
| preventPositionChangeWhenVisible | boolean | true | If `true`, the dropdown picks its side on open (flip runs once, preferring the `position` prop) and then never changes side — scrolling, resizing, and content size changes will not flip the dropdown. The side is recalculated fresh on the next open. Does not affect the `shift` middleware. Set to `false` to keep flip active and allow the dropdown to re-flip on every change. |
| radius | MantineRadius \| number | theme.defaultRadius | Key of `theme.radius` or any valid CSS value to set border-radius |
| shadow | MantineShadow | - | Key of `theme.shadows` or any other valid CSS `box-shadow` value |
| transitionProps | TransitionProps | { duration: 150, transition: 'fade' } | Props passed down to the `Transition` component. Use to configure duration and animation type. |
| trapFocus | boolean | - | If set, focus is trapped within the menu dropdown when it is opened |
| width | PopoverWidth | 'max-content' | Dropdown width, or `'target'` to make dropdown width the same as target element |
| withArrow | boolean | false | Determines whether component should have an arrow |
| withInitialFocusPlaceholder | boolean | true | Adds a hidden focusable element at the start of the dropdown to prevent unexpected focus jumps when opening with keyboard. Set to false if you need custom focus management. |
| withOverlay | boolean | false | Determines whether the overlay should be displayed when the dropdown is opened |
| withinPortal | boolean | true | Determines whether dropdown should be rendered within the `Portal` |
| zIndex | string \| number | 300 | Dropdown `z-index` |

**Menubar.Target props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| children | React.ReactNode | required | Target label |
| refProp | string | 'ref' | Key of the prop used to get element ref, useful for forwarding refs to custom components |

**Menubar.Dropdown props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|


#### Styles API

Menubar component supports Styles API. With Styles API, you can customize styles of any inner element. Follow the documentation to learn how to use CSS modules, CSS variables and inline styles to get full control over component styles.

**Menubar selectors**

| Selector | Static selector | Description |
|----------|----------------|-------------|
| root | .mantine-Menubar-root | Root element with `role="menubar"` |
| target | .mantine-Menubar-target | `Menubar.Target` top-level trigger button |

**Menubar data attributes**

| Selector | Attribute | Condition | Value |
|----------|-----------|-----------|-------|
| target | data-expanded | Associated menu is opened | - |
