Skip to content
// EFFECT DAYS 2026

Menubar unstable

A row of menus, such as File, Edit and View along the top of an editor, that the arrow keys move through as one control.

Menubar is headless: it keeps one of its triggers in the page's Tab order, moves focus between them, and tells each Menu drawn inside it that it sits in a menubar. Each menu is an ordinary Menu call inside the root, and the consumer owns which one is open, as for any Menu.

Anatomy

Part Element
root <div> around the menus

The root takes the consumer's builder and returns it, and the consumer draws the menus inside it. It adds no markup. A menu inside a menubar draws its trigger and positioner as it would anywhere else: the trigger becomes a menuitem of the menubar, the popup opens below it, or beside it in a vertical menubar, and lines up with its start.

Data attributes

On the root, data-orientation holds the orientation, and these are present with an empty value or absent:

  • data-modal
  • data-has-submenu-open: while one of its menus is open

A menu's parts keep their Menu data attributes. When the open menu moves to another trigger from the keyboard or the pointer, the positioner and the popup of the menu that opens get data-instant="group", and so do those of the menu that closes when focus moves to the other one: turn the transitions off then.

Keyboard

One trigger is in the page's Tab order: the one that last had focus, or the first enabled one. Before mounting, including in server-rendered HTML, an enabled menubar uses the root as its Tab stop instead. On mount, focus on the root moves to the first enabled trigger. On a trigger, ArrowRight and ArrowLeft, or ArrowDown and ArrowUp in a vertical menubar, move focus to the next and the previous trigger, and Home and End to the first and the last. Focusing a trigger opens nothing. Enter and Space open its menu, and so do ArrowDown and ArrowUp, on the first or the last item, or, in a vertical menubar, the arrow key that points away from the bar.

In an open menu of a horizontal menubar, ArrowRight and ArrowLeft open the next and the previous menu, unless the highlighted item opens a submenu or the key closes the submenu that has focus. In a vertical menubar the arrow key that points back at the bar closes the menu. Escape closes it, and focus goes back to its trigger.

Pointer

A press on a trigger opens its menu, and another press closes it. Hovering a trigger opens nothing until one of the menus is open: then hovering another trigger opens its menu at once, and the open one closes.

Usage

Keep which menu is open as one value in the Model. A menu that closes because another one opened can report RequestedClose after the other's RequestedOpen, so clear the value only while it still names the menu that reports it.

Draw each menu's trigger and positioner inside the root: the menubar finds its triggers there, in document order. A menu's own modal, openOnHover and delay don't apply in a menubar. The menubar's modal does, and the triggers and the empty parts of the bar stay clickable over the modal layer. A disabled menubar disables every menu in it. The menubar follows the nearest DirectionProvider above it or, without one, the root's CSS direction.

Example A File and an Edit menu, with the open one in the consumer's Model

import { UiSchema } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { Menu, Menubar } from "effect/ui/kit"
import { Effect, Schema } from "effect"
const menus = [
{ name: "File", items: [{ value: "new", label: "New" }, { value: "save", label: "Save" }] },
{ name: "Edit", items: [{ value: "undo", label: "Undo" }, { value: "redo", label: "Redo" }] }
]
const EditorMessage = UiSchema.TaggedEnum({
RequestedOpenMenu: { menu: Schema.String },
RequestedCloseMenu: { menu: Schema.String },
PickedAction: { value: Schema.String }
})
const Editor = Html.component({
name: "Editor",
model: Schema.Struct({ open: Schema.NullOr(Schema.String) }),
message: EditorMessage
}).make({
init: () => ({ open: null }),
update: {
RequestedOpenMenu: ($, { menu }) => $.evolve({ open: menu }),
RequestedCloseMenu: ($, { menu }) => $.model.open === menu ? $.evolve({ open: null }) : $.model,
PickedAction: ($) => $.model
},
view: (h, model) =>
Menubar(h, {
props: {},
view: (menubar) =>
menubar.root(h.div.class("menubar")).children(
menus.map(({ items, name }) =>
Menu(h, {
key: name,
props: { open: model.open === name, items },
onEmit: {
RequestedOpen: () => EditorMessage.RequestedOpenMenu({ menu: name }),
RequestedClose: () => EditorMessage.RequestedCloseMenu({ menu: name }),
Picked: ({ value }) => EditorMessage.PickedAction({ value }),
Highlighted: () => undefined,
RequestedQuery: () => undefined,
Settled: () => undefined
},
view: (menu) =>
h.div(
menu.trigger({ element: h.button }).children(name),
menu.positioner(h.div).children(
menu.popup(h.div).children(
items.map((item) => menu.item({ element: h.div, value: item.value }).children(item.label))
)
)
)
})
)
)
})
})
// The bar is a menubar, and each trigger is one of its items.
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Editor, {}))
if (!/<div[^>]* role="menubar"/.test(html)) throw new Error("the root isn't a menubar")
if (!/<button[^>]* role="menuitem"[^>]*>Edit</.test(html)) throw new Error("the trigger isn't a menubar item")
3 exports Since v4.2.0 Source

Components

Models

Schemas