Skip to content
// EFFECT DAYS 2026

Menu unstable

A button that opens a list of actions, links, checkbox and radio items, and submenus.

Menu is headless: it owns the keyboard and pointer behaviour, focus, placement and the data attributes, and the consumer draws the markup. The consumer owns whether the popup is open, passes it as open, and stores what RequestedOpen and RequestedClose ask for. Picked reports the item the user chose. items lists every item with its label, in the order they're drawn, for navigation, typeahead and filtering. A checkbox or radio item is checked when its entry has checked: true.

Anatomy

Part Element
trigger <button> that opens the popup, one or several
contextTrigger <div> that opens it at the pointer on a right click
submenuTrigger <div> of the parent menu's item that opens a submenu
backdrop <div>, a manual popover under the positioner
positioner <div>, a manual popover placed by the menu
popup <div> inside the positioner
viewport <div> inside the popup, around content that changes
list <div> inside the popup, around the items of a filter
arrow <div> inside the popup
item <div>, one per value
linkItem <a>, one per value
checkboxItem <div>, one per value
checkboxItemIndicator <span> inside a checkbox item, shown while checked
radioGroup <div> around radio items
radioItem <div> inside a radio group, one per value
radioItemIndicator <span> inside a radio item, shown while checked
group <div> around items
groupLabel <div> inside a group
separator <div> between items
input <input> inside the popup that filters the items
clear <button> that empties the input
empty <div> shown while the filter matches nothing
finalFocus any focusable element, focused on close

Each part takes the consumer's builder and returns it with the part applied, and the consumer adds the children. trigger takes an options object, { element }, with the optional fields of MenuTriggerOptions. The items and the indicators take { element, value }, and group and groupLabel take { element, group }, where group is the group of the items inside. item closes the menu when picked and the others don't; a closeOnClick field changes that. The indicators, clear and empty return undefined while they're hidden, and a keepMounted field keeps an indicator drawn. Every item value has to be in items, and an item keys its element with the value.

A submenu is another Menu drawn inside the parent's popup, with the parent's item value as parentItem. Apply both parts to the item that opens it, menu.item({ element: submenu.submenuTrigger(h.div), value }), and own its open like the root's. Picking an item in a submenu closes every menu above it.

The positioner is a manual popover, so it renders in the top layer and needs no portal. The browser gives a popover a border, padding, a background and overflow: auto, so reset those on the positioner and the backdrop and style the popup instead.

In place

With topLayer: false, the backdrop and the positioner render in place as ordinary elements, hidden while closed, and the popup is placed and clipped inside its containing block, as Positioning describes. The backdrop covers that block, and the menu is never modal, whatever modal or a Menubar says. A submenu takes topLayer from its parent unless it sets its own.

CSS variables

Set on the positioner, so the popup inherits them: --anchor-width, --anchor-height, --available-width, --available-height and --transform-origin. With a viewport, the positioner also gets --positioner-width and --positioner-height, the popup's size.

When the viewport moves to another trigger, the popup's --popup-width and --popup-height go from its old size to its new one and back to auto once its transitions finish. Size the popup with them and transition width and height to animate it. The outgoing content sits in a data-previous element with the old size as --popup-width and --popup-height, next to the data-current one.

Data attributes

Each present with an empty value or absent, except data-side, data-align, data-instant, data-activation-direction and data-orientation, which hold a value:

  • trigger, submenuTrigger: data-popup-open, data-pressed, data-disabled
  • contextTrigger: data-popup-open, data-pressed
  • backdrop: data-open / data-closed, data-starting-style, data-ending-style
  • positioner: as the backdrop, and data-side, data-align, data-anchor-hidden, data-instant
  • popup: as the positioner, without data-anchor-hidden, and data-nested
  • arrow: data-side, data-align, data-uncentered
  • viewport: data-activation-direction, such as "right down", data-transitioning, data-instant
  • the items: data-highlighted, data-disabled; checkbox and radio items and their indicators add data-checked / data-unchecked
  • input: data-highlighted while it has focus and no item does
  • separator: data-orientation

data-instant is "click" when the menu opened or closed from the keyboard, "dismiss" after Escape, and "trigger-change" once the popup has moved to another trigger: turn the transitions off then.

Keyboard

On the trigger, Enter and Space open the popup, and ArrowDown and ArrowUp open it on the first or the last enabled item, except inside a vertical Toolbar, which moves focus with them. In the popup the arrow keys of its orientation, Home and End move between items, disabled ones included, and typing moves to the next item whose label starts with what's typed. Enter and Space pick the highlighted item. On a submenu trigger, the arrow key towards the submenu in the parent's direction, Enter and Space open it, and in the submenu the arrow key back in the submenu's direction closes it. Escape closes the popup, or with closeParentOnEsc the whole menu, and Tab closes it and moves focus on from the trigger.

With a filter, focus stays in the input and the highlighted item is its aria-activedescendant. The arrow keys move the highlight, Enter picks the item, and Space picks it while the input is empty. Home and End move the caret once there's text.

Pointer

A mouse press opens the popup, and a release over an item more than 200ms later picks it. With openOnHover, which a submenu has by default, resting on the trigger for delay opens it, and the popup closes closeDelay after the pointer leaves both, unless it's crossing to the popup. On the way to a submenu, the parent's items don't react. Hovering another trigger of an open menu moves the popup to it at once. A trigger's own options override the menu's. A press within 500ms of a hover open keeps it open. A modal menu, the default for a root menu not opened by hovering, locks the page's scroll, blocks presses outside, except on the trigger, and hides the rest of the page from assistive technology with aria-hidden.

A right click on a contextTrigger opens the popup at the pointer, and a touch held still on it for 500ms opens it under the finger, as a ContextMenu does. A menu opened that way is modal, blocks the whole page, closes on Tab and gives focus back to the element that had it, and a menu opened from its trigger behaves as above. The Menu key and Shift+F10 open it against the contextTrigger, which defaults to tabindex="0".

Limits

The menu doesn't read its items from the rendered elements, so items lists them. A trigger carries no payload: RequestedOpen reports its triggerId, so draw the content for that trigger. filter picks a built-in match; for another, pass filter: null and draw only the items that match. MenuTrigger draws a trigger outside the view. The menu follows the nearest DirectionProvider above it or, without one, the trigger's CSS direction.

Example An edit menu with a checkbox item and a submenu, with the open states in the consumer's Model

import { UiSchema } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { Menu } from "effect/ui/kit"
import { Effect, Schema } from "effect"
const targets = [{ value: "email", label: "Email" }]
const EditorMessage = UiSchema.TaggedEnum({
RequestedOpenMenu: {},
RequestedCloseMenu: {},
RequestedOpenShare: {},
RequestedCloseShare: {},
PickedAction: { value: Schema.String, checked: Schema.optional(Schema.Boolean) }
})
const Editor = Html.component({
name: "Editor",
model: Schema.Struct({ open: Schema.Boolean, share: Schema.Boolean, wrap: Schema.Boolean }),
message: EditorMessage
}).make({
init: () => ({ open: false, share: false, wrap: true }),
update: {
RequestedOpenMenu: ($) => $.evolve({ open: true }),
RequestedCloseMenu: ($) => $.evolve({ open: false }),
RequestedOpenShare: ($) => $.evolve({ share: true }),
RequestedCloseShare: ($) => $.evolve({ share: false }),
PickedAction: ($, { checked, value }) => value === "wrap" ? $.evolve({ wrap: checked === true }) : $.model
},
view: (h, model) => {
const events = {
Picked: ({ checked, value }: { readonly value: string; readonly checked?: boolean | undefined }) =>
EditorMessage.PickedAction({ value, checked }),
Highlighted: () => undefined,
RequestedQuery: () => undefined,
Settled: () => undefined
}
return Menu(h, {
props: {
open: model.open,
items: [
{ value: "copy", label: "Copy" },
{ value: "wrap", label: "Wrap lines", checked: model.wrap },
{ value: "share", label: "Share" }
]
},
onEmit: {
...events,
RequestedOpen: () => EditorMessage.RequestedOpenMenu(),
RequestedClose: () => EditorMessage.RequestedCloseMenu()
},
view: (editMenu) =>
h.div(
editMenu.trigger({ element: h.button }).children("Edit"),
editMenu.positioner(h.div).children(
editMenu.popup(h.div).children(
editMenu.item({ element: h.div, value: "copy" }).children("Copy"),
editMenu.checkboxItem({ element: h.div, value: "wrap" }).children(
editMenu.checkboxItemIndicator({ element: h.span, value: "wrap" })?.children("โœ“"),
"Wrap lines"
),
editMenu.separator(h.div),
Menu(h, {
props: { open: model.share, items: targets, parentItem: "share" },
onEmit: {
...events,
RequestedOpen: () => EditorMessage.RequestedOpenShare(),
RequestedClose: () => EditorMessage.RequestedCloseShare()
},
view: (shareMenu) =>
h.div(
editMenu.item({ element: shareMenu.submenuTrigger(h.div), value: "share" }).children("Share"),
shareMenu.positioner(h.div).children(
shareMenu.popup(h.div).children(
shareMenu.item({ element: h.div, value: "email" }).children("Email")
)
)
)
})
)
)
)
})
}
})
// The trigger says it opens a menu, and the checked item is drawn closed.
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Editor, {}))
if (!/<button[^>]* aria-haspopup="menu"[^>]*>Edit</.test(html)) throw new Error("the trigger isn't a menu button")
if (!/role="menuitemcheckbox"[^>]* aria-checked="true"/.test(html)) throw new Error("the checkbox item isn't checked")
26 exports Since v4.2.0 Source

Components

Constructors

Models

Schemas