VerticalMenu is a transient popup that stacks a small number of commands vertically. Like ContextMenu it is anchored, focusable popup content presented by a trigger — never inline page content — but it lays its items out in a column and has no tail.getVerticalMenuAnchorProps(corner) returns the trigger props that place the menu on a given corner. Spread it onto the trigger and drive visibility with the trigger’s tooltip mode.import { type MouseEvent, useLayoutEffect, useRef, useState } from 'react';
import {
Button,
type ButtonHandle,
TooltipMode,
VerticalMenu,
VerticalMenuButton,
VerticalMenuCorner,
getVerticalMenuAnchorProps,
} from '@wearables-ui-toolkit/mrbd';
// bookmarkIcon, bellIcon, and archiveIcon are `IconSource` values you supply;
// savePlace, muteAlerts, and archivePlace are your own command functions.
export function PlaceActions() {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const triggerRef = useRef<ButtonHandle>(null);
const shouldRestoreFocus = useRef(false);
const closeAfterActivation = () => {
shouldRestoreFocus.current = true;
setIsMenuOpen(false);
};
const handleDismiss = () => {
// Ordinary dismissal restores the trigger while focus remains in the menu.
setIsMenuOpen(false);
};
const activateItem = (event: MouseEvent<HTMLElement>, action: () => void) => {
// The popup is a React child of the trigger, so an item click bubbles to
// the trigger's own handler. Stop it before it toggles the menu back open.
event.stopPropagation();
closeAfterActivation();
action();
};
useLayoutEffect(() => {
if (!isMenuOpen && shouldRestoreFocus.current) {
shouldRestoreFocus.current = false;
triggerRef.current?.getElement()?.focus({ preventScroll: true });
}
}, [isMenuOpen]);
return (
<Button
ref={triggerRef}
title="Place actions"
icon={bookmarkIcon}
alwaysShowText
onClick={() => setIsMenuOpen(open => !open)}
tooltipMode={isMenuOpen ? TooltipMode.ALWAYS : TooltipMode.NONE}
tooltipContentDescription="Place actions"
tooltipContent={
<VerticalMenu aria-label="Place actions" onDismissRequest={handleDismiss}>
<VerticalMenuButton
text="Save place"
icon={bookmarkIcon}
onClick={event => activateItem(event, savePlace)}
/>
<VerticalMenuButton
text="Mute alerts"
icon={bellIcon}
onClick={event => activateItem(event, muteAlerts)}
/>
<VerticalMenuButton
text="Archive"
icon={archiveIcon}
onClick={event => activateItem(event, archivePlace)}
/>
</VerticalMenu>
}
{...getVerticalMenuAnchorProps(VerticalMenuCorner.ABOVE_RIGHT)}
/>
);
}
onDismissRequest callback can clear the open state directly. The anchored-popup infrastructure restores the trigger when the closing menu still owns focus. Keep the explicit layout-effect restoration for item activation or a handler that moves focus before closing.onKeyDownCapture runs first. Calling preventDefault() there stops the menu from handling that key at all.<VerticalMenu
aria-label="Filters"
onDismissRequest={closeMenu}
onKeyDownCapture={event => {
if (event.key === 'Escape' && hasUnsavedFilter) {
event.preventDefault();
confirmDiscard();
}
}}
>
{/* items */}
</VerticalMenu>
VerticalMenuProps. It builds on StaticContainerProps: the menu owns contentClip, height, material, role, width, and raw onKeyDown, so those are removed from the type, and onKeyDownCapture is redeclared as the interception hook described below. The remaining container props — shapeProvider, contentClassName, style, and the layout-transition props — are forwarded to StaticContainer. The forwarded ref lands on the popup root element.| Prop | Type | Default | Description |
|---|---|---|---|
children | VerticalMenuButton element, or a readonly array of them | — | The menu items. |
onDismissRequest | (reason: VerticalMenuDismissReason) => void | — | Called when Back, its desktop Escape equivalent, or focus navigation asks to close the menu. Clear your open state here. Trigger focus is restored automatically when the closing popup still owns focus; restore it explicitly only when your dismissal path moved focus elsewhere. |
autoFocusFirstItem | boolean | true | Moves focus to the first eligible item once the popup is positioned. |
onKeyDownCapture | KeyboardEventHandler<HTMLDivElement> | — | Sees key events before the menu does. Call preventDefault() to keep the menu from handling one. |
aria-label | string | 'Menu' | Accessible name for the popup. |
className | string | '' | Extra class on the popup root. |
contentClassName | string | '' | Extra class on the content wrapper that holds the items. |
shapeProvider | ShapeProvider | Medium rounded rectangle | Geometry used for clipping and material paths. |
getVerticalMenuAnchorProps(corner) returns a VerticalMenuAnchorProps object to spread onto the trigger. It makes the popup focusable, selects an above or below placement, disables the tail, and supplies the target rectangle that aligns the fixed-width menu to the chosen horizontal edge of the trigger. Spread it after your own tooltip props so it wins.| Member | Value | Placement |
|---|---|---|
ABOVE_LEFT | 'above-left' | Above the trigger, aligned to its left edge. |
ABOVE_RIGHT | 'above-right' | Above the trigger, aligned to its right edge. |
BELOW_LEFT | 'below-left' | Below the trigger, aligned to its left edge. |
BELOW_RIGHT | 'below-right' | Below the trigger, aligned to its right edge. |
ABOVE_RIGHT, so the menu grows upward and toward the interior of the display instead of pushing its material and glow off the right edge. Use a BELOW_* corner only for a genuinely top-edge trigger with verified room beneath it.| Member | Value | Meaning |
|---|---|---|
ESCAPE | 'escape' | System Back, or Escape during desktop testing, was requested while the menu was focused. |
NAVIGATION | 'navigation' | Up or Down tried to move focus past the first or last item. |
getVerticalMenuAnchorProps. Every field is a tooltip prop understood by any control built on InteractableBase, so the object spreads straight onto the trigger.| Field | Type | Value | Description |
|---|---|---|---|
tooltipFocusable | true | Always true | Lets the popup take focus, which makes the menu operable and gives it the transient Back behavior. Desktop Escape follows the same dismissal path. |
tooltipPosition | TooltipPosition | ANCHORED for an ABOVE_* corner, ANCHORED_BOTTOM for a BELOW_* corner | Preferred vertical side. |
tooltipShowTail | false | Always false | A vertical menu is edge-aligned, not aimed at a point, so it never draws a tail. |
tooltipTargetRectProvider | TooltipTargetRectProvider | Corner-specific | Returns the anchor-relative rectangle the menu centres on, inset from the chosen edge by half the menu width so the menu lines up with that edge. |
autoFocusFirstItem left on, the first eligible item is focused once the popup reports that it is positioned, and that focus is re-asserted for a short settling period so the trigger’s release animation cannot strand the menu.onDismissRequest with NAVIGATION.onDismissRequest with ESCAPE and follows the same dismissal path. Closing the menu another way removes the temporary entry. The infrastructure returns focus to the trigger when the menu closes while focus remains inside it. Do not add another Back listener or history entry around the menu.onDismissRequest the menu deliberately does not claim Back, desktop Escape, or edge navigation; the request keeps bubbling so something else can handle it.onKeyDownCapture runs before the menu’s own handling for every key. If it calls preventDefault(), the menu leaves that key alone.menu and is named Menu unless you pass aria-label. Give it a name that says what the commands act on.tooltip. Set tooltipContentDescription on the trigger so that wrapper is announced with the same meaning as the menu itself.menuitem named by its own text.getVerticalMenuAnchorProps(corner) last on the trigger so it is not overwritten by an earlier tooltip prop.onDismissRequest so Back and its desktop Escape equivalent can close the menu.