@objectifthunes/whiteboard
OVERLAYS

Menu

Dropdown menu with full arrow-key navigation. MenuItem, MenuDivider and MenuLabel compose the panel.


PREVIEW

Last action: nothing yet

SOURCE
import { Menu, MenuItem, MenuDivider, MenuLabel, usePopover, Button, Kbd } from '@objectifthunes/whiteboard'

const { anchorRef, open, toggle, close } = usePopover<HTMLButtonElement>()

<Button ref={anchorRef} variant="secondary" onClick={toggle} aria-haspopup="menu">Actions</Button>

<Menu open={open} onClose={close} anchorRef={anchorRef} align="end">
  <MenuLabel>This invoice</MenuLabel>
  <MenuItem icon={<Pencil size={13} />} hint={<Kbd>E</Kbd>} onSelect={edit}>Edit</MenuItem>
  <MenuItem disabled>Share (needs a paid plan)</MenuItem>
  <MenuDivider />
  <MenuItem tone="danger" onSelect={remove}>Delete</MenuItem>

  {/* toggles keep the menu open, so you can tick several */}
  <MenuItem checked={dense} keepOpen onSelect={toggleDense}>Dense rows</MenuItem>
</Menu>
NOTES

Arrow keys move between items and wrap around, Home and End jump to the ends, Enter and Space activate, Escape closes. The first item takes focus on open, so the keyboard works without a click first.

Selecting an item closes the menu, handled by delegation on the list rather than by each row. That keeps MenuItem a dumb row that only knows its own onSelect — no context, no store, nothing to wire at the call site.

keepOpen opts a row out of that, which is what you want for checked toggle rows: ticking two options should not mean opening the menu twice. The columns menu in TableToolbar is built exactly this way.

For a searchable list of options use Combobox. For a filter panel with real checkboxes and an Apply button, use Popover directly — a menu is for actions, not for forms.