A menu, opened by a button or at a point (a context menu), whose rows may
open submenus, in three layers, each built on the one before.
The fork (MenuView, ./menuView.ts) is @foldkit/ui's Menu view with a
toView seam upstream lacks; the Menu's Model, update and Mounts stay
upstream's.
The panel adapter (MenuSlots, resolve, toView, fluid,
overlayBars, drawAtPoint, pointTarget) styles a Menu drawn through
the fork, whoever keeps its Model: toView is that Menu's toView. Menubar
draws its menus through it, and so does an application that folds
@foldkit/ui's Menu itself, for typed items or groups, which the
component's rows do not have; drawAtPoint and pointTarget open such a
Menu at a point. One recipe, Recipes.Menu, styles every panel and the
rows' words and chevrons.
The component (init, update, view, target) is a menu of string rows
drawn through the adapter. Its Model holds @foldkit/ui Menus, one for the
menu and one per row with items, so each keeps its own keys, typeahead and
rows, and update sorts out which Menu a key belongs to. A plain menu is a
menu none of whose rows have items, and a context menu is the same menu
with opensAt: 'point': a submenu, a button and a point are each one
difference in the same Model.
Submenus are one level deep. A submenu is drawn inside its row, so its own
anchor places it beside the row: its button is a mark the size of the row
that nothing sees, focuses or presses. Being inside the row, every key,
click and release in a submenu also bubbles to the menu's panel, which
answers in the Menu's Messages. update reads those against its own Model:
while a submenu is open, focus is in it, so the menu's key Messages and its
blur are the submenu's and are dropped, and the menu's Closed is the
submenu's Escape. The submenu's own Closed is dropped for that reason, and
it draws no click-away: the menu's serves both, closing everything on
pointerdown. The keys the Menu does not answer (ArrowRight, ArrowLeft, and
Tab while a submenu is open) are heard on the menu's panel.
A submenu's row is a menuitem with aria-haspopup="menu" and
aria-expanded. ArrowRight, Enter or Space on it opens the submenu with its
first row active, and ArrowLeft or Escape closes it back to that row; under
direction: 'rtl' the submenu opens to the left and the two arrows swap.
Resting the pointer on it opens it after a short delay, and resting on
another row closes it. Choosing a submenu's row closes the whole menu.
At a point, target goes on the area that opens the menu: a right press
records its point, and the contextmenu that follows (a right press,
Shift+F10 or the ContextMenu key, the browser's own menu kept shut) opens
the menu there, its button a mark of no size the Menu's anchor places the
rows against. Opened from the keyboard, with no press before it, the mark
stands where the menu is drawn.
A row that is on or off: menuitemcheckbox or menuitemradio, with
aria-checked. Choosing it sends Selected and leaves the menu open, as
Base UI's checkbox and radio items do, so several can be set in one
visit; the application keeps checked, and a radio row's group is the
rows of its group.
The application's own Menu: base for every use, presets chosen at a use
with preset, and the call over both. mixins here and at the call
concatenate, so a use may draw with the base's alone.
A draw for toView that opens a @foldkit/ui Menu at a point, for an
application that folds the Menu itself: its button becomes a mark of no
size at point (where it is drawn, with none), which the Menu's anchor
places the rows against, so give the anchor no gap. The application
keeps the point, from pointTarget's press, and opens the Menu with its
Opened Message on pointTarget's onOpen.
What moves the open panel's highlight: on its rows, one highlight
follows the pointer to the nearest row (--fk-popup-hover-*),
and to the row the keys mark (data-active) while the pointer is away.
Pass them beside the style; until they run, each row marks itself.
The view inputs that set rows in their groups under their headings, for
a Menu's viewInputs; none when no row names a group. A group is keyed by
its first row, since a heading's words make no id.
Menu is a nested Submodel: one button/backdrop/items group plus an
item per entry (and group/heading/separator where the caller
groups), so the resolver runs once per bundle and each base attribute
passes through by identity.
The button owns click (and pointerdown/keydown while enabled); an
item owns click while interactive. A Behavior adding its own handler to
one of those is a conflict, not a second silent owner. Disabled buttons
and items publish no click, so the contract still lists it as allowed.
What draws the open panel's scrollBar over its scroll (ScrollBars),
in place of the browser's bar, on a pointer that can hover. Pass it beside
the style when the menu scrolls (itemsScrollAttributes); without a
scroll there is no bar.
The attributes of the area a menu opens in at a point: a right press
reports its point, and the contextmenu that follows asks to open, the
browser's own menu kept shut. target is this for the component.
The Menu view inputs that put rows in the Menu: its items are the rows'
values, so a row is told from another by its value, its disabled state is
asked by value, and typeahead matches the labels. The rows' content is
drawn by withRows (and the submenu's row by view), not by itemToConfig.
The attributes of the area a menu with opensAt: 'point' opens in: a right press records
its point, and its contextmenu opens the menu; a finger or a pen held there HOLD_MS
opens it too, as iOS fires no contextmenu for one. Give the area
-webkit-touch-callout: none and user-select: none, or iOS shows its own callout over it.
A resolved menu with rows drawn in its rows, by index: each row's words
(label), a checkbox or radio row's role, aria-checked and check
mark, an icon, a hint, a shortcut and its aria-keyshortcuts, a tone, and a separator
before every group after the first. Upstream draws a separator only from
attributes an application cannot write, so it is drawn here.