Skip to main content

menubar

A visually persistent menu common in desktop applications that provides quick access to a consistent set of commands.

Philosophy

Menubars bring desktop-application navigation patterns to the web. The keyboard model (arrow keys between menus, type-ahead navigation, submenu traversal) follows established platform conventions and is powered by @gentleduck/primitives/menubar.

Installation


npx @gentleduck/cli add menubar

npx @gentleduck/cli add menubar

Usage

import {
  Menubar,
  MenubarContent,
  MenubarItem,
  MenubarMenu,
  MenubarSeparator,
  MenubarShortcut,
  MenubarTrigger,
} from "@/components/ui/menubar"
import {
  Menubar,
  MenubarContent,
  MenubarItem,
  MenubarMenu,
  MenubarSeparator,
  MenubarShortcut,
  MenubarTrigger,
} from "@/components/ui/menubar"
<Menubar>
  <MenubarMenu>
    <MenubarTrigger>File</MenubarTrigger>
    <MenubarContent>
      <MenubarItem>
        New Tab <MenubarShortcut>⌘T</MenubarShortcut>
      </MenubarItem>
      <MenubarItem>New Window</MenubarItem>
      <MenubarSeparator />
      <MenubarItem>Share</MenubarItem>
      <MenubarSeparator />
      <MenubarItem>Print</MenubarItem>
    </MenubarContent>
  </MenubarMenu>
</Menubar>
<Menubar>
  <MenubarMenu>
    <MenubarTrigger>File</MenubarTrigger>
    <MenubarContent>
      <MenubarItem>
        New Tab <MenubarShortcut>⌘T</MenubarShortcut>
      </MenubarItem>
      <MenubarItem>New Window</MenubarItem>
      <MenubarSeparator />
      <MenubarItem>Share</MenubarItem>
      <MenubarSeparator />
      <MenubarItem>Print</MenubarItem>
    </MenubarContent>
  </MenubarMenu>
</Menubar>

Component Composition

Loading diagram...

RTL Support

Set dir="rtl" on Menubar for a local override, or set DirectionProvider once at app/root level for global direction.

Motion

Use MotionMenubarContent for a spring-powered enter animation with blur powered by motion. Exit uses the primitive's built-in CSS animation.

API Reference

Components in this file wrap @gentleduck/primitives/menubar.

PropTypeDefaultDescription
valuestring''Controlled currently-open menu value
defaultValuestring''Initial open menu value for uncontrolled usage
onValueChange(value: string) => void-Callback when open menu value changes
loopbooleantrueLoops roving focus across triggers
dir'ltr' | 'rtl'-Text direction. Resolved by primitives useDirection (dir prop -> DirectionProvider -> 'ltr').
classNamestring-Additional CSS classes
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Root>-Additional props inherited from MenubarPrimitive.Root
PropTypeDefaultDescription
valuestringauto-generatedUnique identifier for this menu
onOpenChange(open: boolean) => void-Callback when the menu opens or closes
childrenReact.ReactNode-Trigger and content elements for this menu
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Menu>-Additional props inherited from MenubarPrimitive.Menu
PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReact.ReactNode-Trigger label/content
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Trigger>-Additional props inherited from MenubarPrimitive.Trigger
PropTypeDefaultDescription
containerHTMLElement-Optional portal container
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Portal>-Additional props inherited from MenubarPrimitive.Portal
PropTypeDefaultDescription
classNamestring-Additional CSS classes
side'top' | 'right' | 'bottom' | 'left'-Preferred side relative to the trigger
align'start' | 'center' | 'end''start'Alignment on the chosen side
sideOffsetnumber8Main-axis offset from trigger
alignOffsetnumber-4Cross-axis offset from trigger
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Content>-Additional props inherited from MenubarPrimitive.Content
PropTypeDefaultDescription
insetbooleanfalseAdds start padding for alignment with indicators/icons
classNamestring-Additional CSS classes
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Item>-Additional props inherited from MenubarPrimitive.Item
PropTypeDefaultDescription
checkedboolean-Controlled checked state
onCheckedChange(checked: boolean) => void-Callback when checked state changes
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.CheckboxItem>-Additional props inherited from MenubarPrimitive.CheckboxItem
PropTypeDefaultDescription
valuestring-Controlled selected value
onValueChange(value: string) => void-Callback when selected value changes
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.RadioGroup>-Additional props inherited from MenubarPrimitive.RadioGroup
PropTypeDefaultDescription
valuestring(required)Value represented by this radio item
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.RadioItem>-Additional props inherited from MenubarPrimitive.RadioItem
PropTypeDefaultDescription
insetbooleanfalseAdds start padding for alignment
classNamestring-Additional CSS classes
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Label>-Additional props inherited from MenubarPrimitive.Label
PropTypeDefaultDescription
classNamestring-Additional CSS classes
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Separator>-Additional props inherited from MenubarPrimitive.Separator
PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReact.ReactNode-Shortcut hint content (for example, ⌘S)
...propsReact.HTMLAttributes<HTMLSpanElement>-Additional props to spread to the shortcut <span>
PropTypeDefaultDescription
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Group>-Additional props inherited from MenubarPrimitive.Group
PropTypeDefaultDescription
childrenReact.ReactNode-Sub-trigger and sub-content elements
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.Sub>-Additional props inherited from MenubarPrimitive.Sub
PropTypeDefaultDescription
insetbooleanfalseAdds start padding for alignment
classNamestring-Additional CSS classes
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.SubTrigger>-Additional props inherited from MenubarPrimitive.SubTrigger
PropTypeDefaultDescription
classNamestring-Additional CSS classes
side'top' | 'right' | 'bottom' | 'left'-Preferred side relative to the sub-trigger
align'start' | 'center' | 'end'-Alignment on the chosen side
sideOffsetnumber-Main-axis offset from sub-trigger
alignOffsetnumber-Cross-axis offset from sub-trigger
...propsReact.ComponentPropsWithoutRef<typeof MenubarPrimitive.SubContent>-Additional props inherited from MenubarPrimitive.SubContent

MotionMenubarContent

Same props as MenubarContent. Adds spring scaleIn+blur enter animation via motion. Exit uses the primitive's CSS animation. Requires the motion package.