---
title: "Menubar · UI SDK — StyleX Blocks"
description: "A horizontal bar of application menus with arrow-key navigation between them, checkable items, and radio groups."
url: "https://stylexblocks.com/components/ui-sdk/menubar/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Menubar

A horizontal bar of application menus with arrow-key navigation between them, checkable items, and radio groups.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/menubar.md), [Base UI](https://stylexblocks.com/components/base-ui/menubar.md)
- Category: Display
- Variants: subtle, solid
- Sizes: sm, md
- HTML page: https://stylexblocks.com/components/ui-sdk/menubar/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add menubar
```

Equivalent: `npx shadcn add @stylexblocks/menubar`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/menubar.json

## Usage

```tsx
import { Menubar } from "#components/ui/ui-sdk/menubar.tsx";

export function Example() {
  return (
    // UI SDK's Menubar hosting UI SDK menus: the engine handles the single
    // tab stop, ←/→ between menus, and hover switching. Content is a native
    // popover in the top layer: no Portal or Positioner. size/variant
    // resolve once on Root; every menu inherits them.
    <Menubar.Root size="md">
      <Menubar.Menu onAction={(value) => console.log(value)}>
        <Menubar.Trigger>File</Menubar.Trigger>
        <Menubar.Content>
          <Menubar.Item value="new-tab">
            <Menubar.ItemText>New tab</Menubar.ItemText>
            <Menubar.ItemCommand>⌘T</Menubar.ItemCommand>
          </Menubar.Item>
        </Menubar.Content>
      </Menubar.Menu>
      <Menubar.Menu onAction={(value) => console.log(value)}>
        <Menubar.Trigger>Edit</Menubar.Trigger>
        <Menubar.Content>
          <Menubar.Item value="undo">
            <Menubar.ItemText>Undo</Menubar.ItemText>
            <Menubar.ItemCommand>⌘Z</Menubar.ItemCommand>
          </Menubar.Item>
        </Menubar.Content>
      </Menubar.Menu>
    </Menubar.Root>
  );
}
```

## Source

`components/ui/ui-sdk/menubar.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import {
  Menu as UiSdkMenu,
  MenuCheckboxItem,
  MenuContent,
  MenuGroup,
  MenuGroupLabel,
  MenuItem,
  MenuItemIndicator,
  MenuRadioGroup,
  MenuRadioItem,
  MenuSeparator,
  MenuShortcut,
  MenuSub,
  MenuSubContent,
  MenuSubTrigger,
  MenuTrigger,
} from "@ui-sdk/react/menu";
import { Menubar as UiSdkMenubar } from "@ui-sdk/react/menubar";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  resolveSlotStyles,
  type StyleOverrideProps,
} from "#lib/recipe-props.ts";
import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";
import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";
import { cursor } from '@stylexblocks/ui/tokens/cursor.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { letterSpacings } from '@stylexblocks/ui/tokens/letter-spacings.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'

const menuContent = stylex.create({
  base: {
    outline: 'none',
    color: semanticColors.fg,
    maxHeight: 'var(--available-height)',
    '--menu-z-index': zIndices.layer3,
    zIndex: 'calc(var(--menu-z-index) + var(--layer-index, 0))',
    overflowY: 'auto',
    scrollbarWidth: 'thin',
    transformOrigin: 'var(--transform-origin)',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'fade-in, slide-from-top',
      ':is([data-closed], [data-state="closed"])': 'fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.fast,
      ':is([data-closed], [data-state="closed"])': durations.faster,
    },
  },
})

const menuContentSizes = stylex.create({
  sm: {
    minWidth: '8rem',
    padding: spacing._1,
    borderRadius: semanticRadii.panel,
  },
  md: {
    minWidth: '8rem',
    padding: spacing._1,
  },
})

const menuItem = stylex.create({
  base: {
    textDecoration: 'none',
    color: semanticColors.fg,
    userSelect: 'none',
    borderRadius: semanticRadii.control,
    width: '100%',
    display: 'flex',
    cursor: {
      default: cursor.menuitem,
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
    alignItems: 'center',
    textAlign: 'start',
    position: 'relative',
    flex: '0 0 auto',
    outline: 'none',
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
  },
})

const menuItemSizes = stylex.create({
  sm: {
    gap: spacing._1,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    minHeight: sizes._6,
    paddingInline: spacing._1_5,
    paddingInlineStart: `var(--menu-item-inset, ${spacing._1_5})`,
  },
  md: {
    gap: spacing._2,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    minHeight: sizes._7,
    paddingInline: spacing._2,
    paddingInlineStart: `var(--menu-item-inset, ${spacing._2})`,
  },
})

const menuItemVariants = stylex.create({
  subtle: {},
  solid: {},
})

const menuItemText = stylex.create({
  base: {
    flex: 1,
  },
})

const menuItemGroupLabel = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    color: semanticColors.fgSubtle,
  },
})

const menuItemGroupLabelSizes = stylex.create({
  sm: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    minHeight: sizes._6,
    paddingInline: spacing._1_5,
  },
  md: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    minHeight: sizes._7,
    paddingInline: spacing._2,
  },
})

const menuIndicator = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    flexShrink: 0,
  },
})

const menuItemCommand = stylex.create({
  base: {
    opacity: 0.6,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    marginInlineStart: 'auto',
    paddingInlineStart: spacing._4,
    letterSpacing: letterSpacings.widest,
  },
})

const menuSeparator = stylex.create({
  base: {
    height: '1px',
    backgroundColor: semanticColors.bgMuted,
    marginBlock: spacing._1,
    marginInline: spacing._1,
  },
})

export type MenuVariant = keyof typeof menuItemVariants

export type MenuSize = keyof typeof menuContentSizes

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis
const menuRecipe = defineSlotRecipe({
  slots: {
    content: { styles: menuContent, sizes: menuContentSizes },
    item: { styles: menuItem, sizes: menuItemSizes, variants: menuItemVariants },
    itemText: { styles: menuItemText },
    itemGroupLabel: {
      styles: menuItemGroupLabel,
      sizes: menuItemGroupLabelSizes,
    },
    indicator: { styles: menuIndicator },
    itemCommand: { styles: menuItemCommand },
    separator: { styles: menuSeparator },
  },
  defaultVariants: { size: "md", variant: "subtle" },
});

// The dropdowns are the menu recipe unchanged (plus Menu's local chrome);
// only the bar and its triggers are new. Triggers highlight like menu items
// (bgSubtle) on hover, keyboard focus, and while their menu is open. UI SDK
// menu content is a native popover in the top layer that keeps the browser's
// popover border, margin and background, so the surface resets them here.
const chrome = stylex.create({
  bar: {
    display: "inline-flex",
    alignItems: "center",
    gap: spacing._0_5,
    backgroundColor: semanticColors.bgPanel,
    borderWidth: "1px",
    borderStyle: "solid",
    borderColor: semanticColors.border,
    borderRadius: semanticRadii.panel,
    boxShadow: semanticShadows.xs,
  },
  trigger: {
    display: "inline-flex",
    alignItems: "center",
    whiteSpace: "nowrap",
    userSelect: "none",
    borderWidth: 0,
    borderRadius: semanticRadii.control,
    color: semanticColors.fg,
    fontWeight: fontWeights.medium,
    outline: "none",
    cursor: {
      default: cursor.button,
      ":is(:disabled, [data-disabled])": "not-allowed",
    },
    opacity: {
      default: null,
      ":is(:disabled, [data-disabled])": 0.5,
    },
    backgroundColor: {
      default: "transparent",
      ":hover": semanticColors.bgSubtle,
      ":focus-visible": semanticColors.bgSubtle,
      ':is([data-state="open"], [data-open], [data-highlighted])':
        semanticColors.bgSubtle,
    },
  },
  content: {
    "--menu-z-index": zIndices.dropdown,
    margin: 0,
    borderWidth: 0,
    backgroundColor: semanticColors.bgPanel,
    borderRadius: semanticRadii.panel,
    boxShadow: semanticShadows.overlay,
  },
  item: {
    paddingBlock: spacing._1,
    color: {
      default: null,
      ":is([data-destructive])": semanticColors.fgError,
    },
    backgroundColor: {
      default: null,
      ":is([data-highlighted])": semanticColors.bgSubtle,
    },
  },
  itemCommand: {
    marginInlineStart: "auto",
    paddingInlineStart: spacing._4,
  },
  indicator: {
    width: "1rem",
    height: "1rem",
    display: "inline-flex",
    visibility: {
      default: "visible",
      ":is([hidden], [data-unchecked])": "hidden",
    },
  },
});

const barSizes = stylex.create({
  sm: { padding: spacing._0_5 },
  md: { padding: spacing._1 },
});

const triggerSizes = stylex.create({
  sm: {
    height: sizes._6,
    paddingInline: spacing._1_5,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  md: {
    height: sizes._7,
    paddingInline: spacing._2,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
});

function CheckIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m3.5 8.5 3 3 6-7" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

const { withProvider, withContext } = createSlotRecipeContext(menuRecipe);

const itemStyles = (v: Record<string, string>) => [
  ...resolveSlotStyles(menuRecipe.slots.item, v),
  chrome.item,
];
const contentStyles = (v: Record<string, string>) => [
  ...resolveSlotStyles(menuRecipe.slots.content, v),
  chrome.content,
];

const StyledContent = withContext(MenuContent, contentStyles, "MenubarContent");

function Content(props: React.ComponentProps<typeof StyledContent>) {
  const { sideOffset = 6, align = "start", ...rest } = props;
  return <StyledContent sideOffset={sideOffset} align={align} {...rest} />;
}
Content.displayName = "MenubarContent";

const StyledItemIndicator = withContext(
  MenuItemIndicator,
  (v) => [...resolveSlotStyles(menuRecipe.slots.indicator, v), chrome.indicator],
  "MenubarItemIndicator",
);

function ItemIndicator(
  allProps: Omit<React.ComponentProps<typeof MenuItemIndicator>, "style"> & StyleOverrideProps,
) {
  const { children, keepMounted = true, ...rest } = allProps;
  return (
    <StyledItemIndicator keepMounted={keepMounted} {...rest}>
      {children ?? <CheckIcon />}
    </StyledItemIndicator>
  );
}
ItemIndicator.displayName = "MenubarItemIndicator";

/**
 * Menubar — UI SDK's Menubar hosting UI SDK menus, wearing the menu slot
 * recipe: the engine supplies `role="menubar"`, the single tab stop, ←/→
 * between menus (opening the neighbour while one is open), and hover
 * switching; each `Menubar.Menu` is a regular UI SDK `Menu` whose content is
 * a native popover in the top layer, so there is no Portal or Positioner:
 * placement props go on `Content`. Triggers carry `data-open` while their
 * menu is open. `<Menubar.Root size variant>` resolves the recipe once; every
 * part inherits it through context and composes via `render`. One
 * `ItemIndicator` serves checkbox and radio items.
 */
export const Menubar = {
  Root: withProvider(
    UiSdkMenubar,
    (v) => [chrome.bar, barSizes[v.size]],
    "MenubarRoot",
  ),
  Menu: UiSdkMenu,
  Trigger: withContext(
    MenuTrigger,
    (v) => [chrome.trigger, triggerSizes[v.size]],
    "MenubarTrigger",
  ),
  Content,
  Item: withContext(MenuItem, itemStyles, "MenubarItem"),
  SubmenuRoot: MenuSub,
  SubmenuTrigger: withContext(MenuSubTrigger, itemStyles, "MenubarSubmenuTrigger"),
  SubmenuContent: withContext(MenuSubContent, contentStyles, "MenubarSubmenuContent"),
  ItemText: withContext("span", "itemText", "MenubarItemText"),
  Group: MenuGroup,
  GroupLabel: withContext(MenuGroupLabel, "itemGroupLabel", "MenubarGroupLabel"),
  CheckboxItem: withContext(MenuCheckboxItem, itemStyles, "MenubarCheckboxItem"),
  RadioGroup: MenuRadioGroup,
  RadioItem: withContext(MenuRadioItem, itemStyles, "MenubarRadioItem"),
  ItemIndicator,
  ItemCommand: withContext(
    MenuShortcut,
    (v) => [...resolveSlotStyles(menuRecipe.slots.itemCommand, v), chrome.itemCommand],
    "MenubarItemCommand",
  ),
  Separator: withContext(MenuSeparator, "separator", "MenubarSeparator"),
};
```
