Actions

Menubar

A persistent row of Dropdown Menus, like an application's File, Edit and View menus.

Class nameTypeDescription
menubarplf:menubarComponentThe row of menus
dropdownplf:dropdownComponentWraps one trigger and its menu
menuplf:menuComponentThe list of items, with dropdown-content
menubar-triggerplf:menubar-triggerPartA menu's trigger button
menu-shortcutplf:menu-shortcutPartA key hint; binds no key
dropdown-contentplf:dropdown-contentPartThe floating panel
menu-itemplf:menu-itemPartA button or link item
menu-titleplf:menu-titlePartA label above items
menu-separatorplf:menu-separatorPartA divider between items
menu-textplf:menu-textPartAn item's text
menu-item-errorplf:menu-item-errorColorA destructive item

Default

Name the bar with aria-label or aria-labelledby, and make every direct child a valid Dropdown Menu; otherwise the bar gets no behavior.

JavaScript

Menubar needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-menubar Marks the bar; needs aria-label or aria-labelledby
data-plf-dropdown-menu Marks each direct child; see the Dropdown Menu hooks
data-plf-align On a menu: start (default in a Menubar), center or end
disabled, aria-disabled="true" An item, or a trigger whose menu cannot open
Method Behavior
PLF.Menubar.getOrCreateInstance(element) Returns the instance, creating it for valid markup
PLF.Menubar.getInstance(element) Returns the instance or null
instance.getState() Returns {open, active}: the open dropdown or null, and the focusable trigger
instance.destroy() Removes listeners and added attributes, and destroys the Dropdown Menus it created

Open or close one menu with its Dropdown Menu methods.

Events

Menubar has no events of its own. Each menu’s plf:dropdown-menu:* events bubble through the bar.

Keyboard

Key Action
Tab Enters or leaves the bar, a single Tab stop
Right Arrow, Left Arrow Move to the next or previous trigger; an open menu moves along
Home, End Move to the first or last trigger
Enter, Space, Down Arrow Open the menu at the first item
Up Arrow Opens the menu at the last item
Escape Closes the menu and focuses its trigger

Inside a menu, the Dropdown Menu keys apply.

React

Menubar from @pelatform/react renders the bar and its keyboard, and each MenubarMenu a trigger with its menu, which keeps its own state, or the application sets it with open.

Prop Values Default
open on MenubarMenu true while the menu is open, which the application changes in onOpenChange Its own state
defaultOpen on MenubarMenu true starts open when the application does not set open false
onOpenChange on MenubarMenu (open, reason), called when the menu opens or closes: trigger (a pointer: its trigger, an item, a press outside, or a hover over its trigger while another menu is open) or keyboard (a key, or the focus leaving it) None
placement on MenubarMenu top, bottom, left, right bottom
align on MenubarMenu start, center, end start
color on MenubarItem error None
onSelect on MenubarItem (event), called when the item is chosen; the menu closes unless it calls event.preventDefault() None

The parts:

Part Element
MenubarMenu A div with dropdown, which holds one trigger and its menu
MenubarTrigger A button with menubar-trigger, which opens its menu and names it
MenubarContent A div with dropdown-content menu: the menu
MenubarItem A button with menu-item
MenubarTitle A div with menu-title
MenubarSeparator An hr with menu-separator
MenubarText A span with menu-text
MenubarShortcut A kbd with menu-shortcut, hidden from assistive technologies

Other props are the element’s own, className and ref included.

Variable Default
--plf-menubar-bg, --plf-menubar-color Surface and text
--plf-menubar-border Subtle border
--plf-menubar-radius Large radius (8px)
--plf-menubar-trigger-active-bg Muted surface, on hover and while a menu is open

The Dropdown Menu variables style the menus.


Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons