Menu

A dropdown menu of actions, checkbox and radio items, shortcuts and submenus.

Pinned, not subscribed.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/menu

Usage

import { Menu } from "./ui/uicontext/components/Menu.ts"
const Message = UiSchema.TaggedEnum({	PickedAction: { value: Schema.String },	ToggledPinned: { pinned: Schema.Boolean },})// `pinned` lives in your Model; the menu asks for the change and your update makes itexport const ProjectMenu = (h: Html.H<typeof Message.Type>, pinned: boolean) =>	Menu(h, {		props: {			label: "Project actions",			entries: [				{ _tag: "Item", value: "rename", label: "Rename" },				{ _tag: "Checkbox", value: "pinned", label: "Pinned", checked: pinned },				{ _tag: "Separator" },				{ _tag: "Item", value: "delete", label: "Delete", tone: "danger" },			],		},		onEmit: {			Picked: ({ value }) => Message.PickedAction({ value }),			Toggled: ({ checked }) => Message.ToggledPinned({ pinned: checked }),			PickedRadio: () => undefined,		},	})

Examples

Radio groups

Each group asks for one value. Checkbox and radio items keep the menu open, so you can change several.

Sorted by updated, comfortable rows.

Row actions

A small icon-only trigger at the end of each row, with the menu lined up to its right edge.

  • Launch brief.pdf 1.2 MB
  • Logo, dark.svg 18 KB
  • Event budget.xlsx 64 KB

Open a row's ⋯ menu.

API reference

MenuComponent

Props

Menu props
NameTypeDescription
labelrequiredstringThe button's text, and its accessible name
entriesrequiredMenuEntry[]The menu's actions, checkbox and radio items, separators, labels and submenus, in order
iconOnlybooleanShow only an icon on the button (the label still names it): "⋯" by default
iconstringThe icon the button shows instead of its label, by name
emphasis"outline" | "ghost"Outline (the default) or ghost, as Button's
size"xs" | "sm" | "md""xs": a 24px icon button, for a row's or a block's actions
align"start" | "end"Which edge of the button the menu lines up with
disabledbooleanThe button can't open the menu

Events

Menu events
EventPayloadDescription
Picked{ value: string }An action was picked
Toggled{ value: string; checked: boolean }A checkbox item asks for checked
PickedRadio{ group: string; value: string }A radio item asks for value in its group

MenuPreviewView function

Options

MenuPreview options
NameTypeDescription
entriesrequiredMenuEntry[]The items to draw, as Menu takes them
highlightedstringThe value of the item drawn as highlighted, as if the pointer were on it

Accessibility

  • Follows the menu button pattern: the arrow keys move, typing jumps to an item, Enter or Space picks, Right opens a submenu and Left closes it.
  • Escape closes the menu and puts focus back on its button. Checkbox and radio items say whether they're checked, and shortcuts are read through aria-keyshortcuts.
  • An icon-only trigger is named by its label.

Source