- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
Installation#
pnpm dlx shadcn@latest add @zui/menubarThe CLI writes components/ui/menubar.tsx, lib/menu.ts, lib/motion.ts and lib/overlay.ts, installs Direction, Icon, Text and Utils, and adds
@rn-primitives/menubar, @rn-primitives/portal, lucide-react-native, react-native-reanimated and
react-native-worklets. The menus draw in the app's PortalHost; see Add a
portal host. Without one they draw nothing, and log an error saying
so while the app is in development.
Usage#
import {
Menubar,
MenubarContent,
MenubarItem,
MenubarMenu,
MenubarSeparator,
MenubarShortcut,
MenubarTrigger,
} from '@/components/ui/menubar';
import { Text } from '@/components/ui/text';<Menubar>
<MenubarMenu>
<MenubarTrigger>
<Text>File</Text>
</MenubarTrigger>
<MenubarContent>
<MenubarItem onPress={newTab}>
<Text>New Tab</Text>
<MenubarShortcut>{'\u2318T'}</MenubarShortcut>
</MenubarItem>
<MenubarSeparator />
<MenubarItem onPress={print}>
<Text>Print...</Text>
</MenubarItem>
</MenubarContent>
</MenubarMenu>
</Menubar>API reference#
Menubar#
Takes every prop of React Native's View. It is a menubar, a row with a border, and one of its menus is open
at a time.
MenubarMenu#
Takes every prop of React Native's View, plus:
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | - |
Without open the menu holds its own state, starting from defaultOpen. With it, the menu follows open, and a
press on its trigger, an item, outside the menu or the back button only reports the change it asks for through
onOpenChange. Opening a menu closes the bar's other one.
MenubarTrigger#
Takes every prop of React Native's Pressable. It is the menu's name in the bar: a press opens the menu, and
another closes it. It is announced as expanded or collapsed and drawn pressed in while its menu is open, and focus
returns to it when the menu closes.
MenubarContent#
Takes the props of DropdownMenuContent, with
upstream's menubar defaults: sideOffset 8 and alignOffset -4, so the menu opens 8px below its trigger and
4px before its start.
The items#
MenubarItem, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarSub, MenubarSubTrigger, MenubarSubContent, MenubarGroup, MenubarLabel, MenubarSeparator, MenubarShortcut and MenubarPortal take the props of their Dropdown menu counterparts and behave as they do. A checkbox or radio item draws its check mark at its start, as upstream's menubar does.
Right to left#
The chevron of a MenubarSubTrigger is mirrored when Direction says
text reads right to left, as upstream's is: its sub-trigger is dropdown-menu's, which carries cn-rtl-flip.
Differences from upstream#
- Upstream's
renderprop becomesasChild, andonClickbecomesonPress, as on every native item. - On a device an open menu covers the bar with the layer that closes it on a press outside, so moving to another menu takes two presses: one to close the open menu and one on the other trigger. The web moves between menus with the arrow keys and the pointer, as upstream does.
- On a device a menu opens above or below its trigger, and a sub-menu opens in place, under its trigger.
- React Native has no
menuitemcheckboxormenuitemradiorole, so on a device a checkbox item is announced as a checkbox and a radio item as a radio button, each with its checked state. The web gives them upstream's roles. - The back button and the iOS escape gesture remove the menu at once, without its exit animation. On the web every menu goes at once: one still fading would close the bar as the arrow keys move to the next menu.
- Upstream's animation runs whatever the system's motion setting. The native one is skipped when the system asks for reduced motion.
portalHostis added on MenubarContent, for an app that draws overlays into aPortalHostof its own.