shadcn.io is an independent project built on shadcn/ui
Components
Free
Menubar for Svelte
File, Edit and View menus in one row, as in a desktop app, with submenus, checkbox and radio items and shortcut hints. A menubar for Svelte on Ark UI.
On this page9 sections
UI library: Ark UI
A menubar is the row of menus across the top of a desktop app, File, Edit and View, each opening a list of commands for the whole window. It suits a web app that works like one: a document editor, a design tool, a code playground, where people expect every command to sit in the same place each time.
For one button that opens a few actions, use a Dropdown Menu. Links that move around a site belong in a Navigation Menu.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Each MenubarMenu is one menu in the bar, with its trigger and its content. Each MenubarItem needs a value, which is how that menu tells your select handler which item was chosen.
Menubar is a div with role="toolbar" and an aria-label of Menu bar, which you can replace with a name for your app's menus. ArrowLeft and ArrowRight move between its triggers, swapped in a right-to-left layout, and Tab leaves the bar from any of them. Each MenubarMenu is a separate Ark UI menu: its trigger is a button that reports aria-haspopup and aria-expanded, and inside it the keys work as in a Dropdown Menu, so they don't reach the next menu.
KeyAction
Tab
Moves focus out of the bar, whichever trigger has it.
Enter
When focus is on a trigger, opens its menu and highlights the first item. On an item, chooses it and closes the menu.
Space
When focus is on a trigger, opens its menu and highlights the first item. On an item, chooses it and closes the menu.
Arrow Down
When focus is on a trigger, opens its menu and highlights the first item. In the menu, highlights the next item.
Arrow Up
When focus is on a trigger, opens its menu and highlights the last item. In the menu, highlights the previous item.
Arrow Right
On a trigger, moves focus to the next trigger, and from the last back to the first. In a menu, opens the submenu when a submenu trigger is highlighted. Right to left, it moves to the previous trigger instead.
Arrow Left
On a trigger, moves focus to the previous trigger, and from the first to the last. In a submenu, closes it and returns to its trigger. Right to left, it moves to the next trigger instead.
Home
Moves focus to the first trigger, or highlights the first item in an open menu.
End
Moves focus to the last trigger, or highlights the last item in an open menu.
EscEscape
Closes the menu and moves focus to its trigger.
Demos
Checkbox
View holds Always Show Bookmarks Bar and Always Show Full URLs above Reload and a disabled Force Reload, and Format holds Strikethrough, Code and Superscript. Each MenubarCheckboxItem takes checked and onCheckedChange from state, and the menu closes after every toggle. The plain items carry inset, which indents their labels to line up with the checked rows.
Radio
Profiles picks one of Andy, Benoit and Luis, with Edit and Add Profile under a separator, and Theme picks Light, Dark or System. Each MenubarRadioGroup holds its value in state, so one choice never clears the other, and the menu closes after a pick. Keep commands such as Edit outside the group, with inset so they line up.
Submenu
In File, a Share submenu with Email link, Messages and Notes sits above Print. In Edit, a Find submenu with Find, Find Next and Find Previous sits between Undo and Redo and the clipboard commands. A submenu holds a cluster that doesn't earn a menu of its own in the bar. Hovering its trigger opens it, and so does ArrowRight.
Icons
File puts a page, a folder and a disk in front of New File, Open Folder and Save, with ⌘N and ⌘S still at the end of their rows, and More holds Settings, Help and a destructive Delete. Every icon has aria-hidden, since the label already names the command. Icons help in a menu people open many times a day.
RTL
The whole bar in Arabic, File to Profiles, inside a div with dir set to rtl so the triggers run from the right and ArrowLeft moves to the next one. Each MenubarMenu also has dir set to rtl, which this file turns into an Arabic locale for that menu, so its text and chevrons turn around, submenus open to the left and ArrowLeft opens them.
FAQ
Should I use a Menubar or a Dropdown Menu?
Use a Menubar when an app has several groups of commands that apply to the whole window, such as File, Edit and View in an editor, and people come back to them all day. Use a Dropdown Menu for one button that opens a handful of actions, such as the ellipsis on a table row or the avatar in a header.
A menubar on a marketing site or a dashboard with three commands is more chrome than it's worth. Links that move people between pages belong in a Navigation Menu.
Can I use a Menubar from the keyboard?
Yes, with one gap. ArrowLeft and ArrowRight move between triggers, Enter, Space or ArrowDown opens a menu, and Escape closes it. Inside an open menu those arrows only work on submenus, so moving from File to Edit means Escape first, then ArrowRight.
The Accessibility section lists every key for Ark UI.
How do I control a checkbox in a Menubar in Svelte?
Pass checked and onCheckedChange to each MenubarCheckboxItem, along with a value, and hold the flag in state, as the Checkbox demo does. The handler receives the new boolean. The menu closes after each toggle, so set closeOnSelect to false on the item when people change several settings in a row.
How do I keep one Menubar radio item selected?
Put the choices in one MenubarRadioGroup and hold the chosen value in state, updating it from onValueChange, which receives an object with the new value in details.value. Exactly one row is marked at a time, and commands such as Edit go outside the group as plain MenubarItem rows, as in the Radio demo.
How do I open a Menubar menu from my own code?
Pass open to that MenubarMenu and update it from onOpenChange, which receives the new flag in details.open. Each MenubarMenu keeps its own state and knows nothing of the others, so when code opens menus in a bar, hold the name of the open one in a single value and derive each menu's open from it.
Why don't the keyboard shortcuts shown in my Menubar work?
MenubarShortcut is a styled span at the end of a row: it prints the keys and listens for nothing. Bind each shortcut yourself, with one keydown listener on the document that checks metaKey or ctrlKey and the key, so the command runs whether or not its menu is open.
Show ⌘ on macOS and Ctrl elsewhere, and only print a hint for a shortcut that really exists. A hint that does nothing teaches people to stop trusting the rest.
Why does the page stop scrolling when a Menubar menu is open?
It doesn't on Ark UI: the menus aren't modal. The page keeps scrolling while one is open, and a click outside closes it. If scrolling stops, something else has locked it, such as a modal dialog the bar sits in.
API Reference
Menubar
<div>data-slot="menubar"
PropType
class?string
Merged with the part's classes.
MenubarMenu
data-slot="menubar-menu"
MenubarTrigger
data-slot="menubar-trigger"
PropType
class?string
Merged with the part's classes.
MenubarContent
data-slot="menubar-content"
PropType
class?string
Merged with the part's classes.
MenubarGroup
data-slot="menubar-group"
MenubarPortal
data-slot="menubar-portal"
MenubarItem
data-slot="menubar-item"
PropType
inset?boolean
Indents it to line up with items that have an icon or indicator.
class?string
Merged with the part's classes.
AttributeType
data-inset?string
Mirrors inset.
data-variant?string
Mirrors variant.
MenubarCheckboxItem
data-slot="menubar-checkbox-item"
PropType
inset?boolean
Indents it to line up with items that have an icon or indicator.
class?string
Merged with the part's classes.
AttributeType
data-inset?string
Mirrors inset.
MenubarRadioGroup
data-slot="menubar-radio-group"
MenubarRadioItem
data-slot="menubar-radio-item"
PropType
inset?boolean
Indents it to line up with items that have an icon or indicator.
class?string
Merged with the part's classes.
AttributeType
data-inset?string
Mirrors inset.
MenubarLabel
data-slot="menubar-label"
PropType
inset?boolean
Indents it to line up with items that have an icon or indicator.
class?string
Merged with the part's classes.
AttributeType
data-inset?string
Mirrors inset.
MenubarSeparator
data-slot="menubar-separator"
PropType
class?string
Merged with the part's classes.
MenubarShortcut
data-slot="menubar-shortcut"
PropType
class?string
Merged with the part's classes.
MenubarSub
data-slot="menubar-sub"
MenubarSubTrigger
data-slot="menubar-sub-trigger"
PropType
inset?boolean
Indents it to line up with items that have an icon or indicator.