VerticalMenu

Updated: Oct 25, 2026
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.
The component owns the popup surface, its drop shadow, its fixed width, initial focus, Up/Down/Home/End movement between items, and the dismissal callback. You own the open state, the anchor corner, and what each item does. The anchored-popup infrastructure restores trigger focus when the menu closes while focus remains inside it. Keep an explicit restoration path for item activation or another close path that moves focus elsewhere first.

Usage

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)}
    />
  );
}
A normal 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.

Intercepting a key before the menu sees it

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>

Props

The full prop type is 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.
PropTypeDefaultDescription
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.

Placing the menu on a corner

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.

Types and enums

VerticalMenuCorner

The first word is the vertical side relative to the trigger; the second is the horizontal edge the menu aligns to.
MemberValuePlacement
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.
Choose the corner from the trigger’s position on screen, not from what the labels mean. A trigger at the right end of a bottom-docked ButtonRail wants 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.

VerticalMenuDismissReason

MemberValueMeaning
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.

VerticalMenuAnchorProps

The shape returned by getVerticalMenuAnchorProps. Every field is a tooltip prop understood by any control built on InteractableBase, so the object spreads straight onto the trigger.
FieldTypeValueDescription
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.
You can build the same object by hand, but prefer the helper: it returns one shared, stable object per corner, so spreading it does not change prop identity between renders.

Behavior

  • Presentation. The popup is rendered by the trigger’s anchored-popup infrastructure into the floating portal root that App supplies. Placing the menu next to the trigger in normal flow bypasses the portal, reflows the page, and makes the corner configuration meaningless.
  • Placement fallback. Because the menu is focusable custom popup content, the placement may flip it to the opposite vertical side when the requested side cannot fit and the other side has more room. Horizontally the popup is clamped inside the tooltip bounds. Pick the corner that is already correct rather than relying on the flip.
  • Sizing. The width is component-owned and deliberately compact, and it narrows on a very small viewport so the menu keeps a margin on both sides. The height grows with the items. Content is not clipped, so focus overshoot nudges stay visible.
  • Initial focus. With 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.
  • Movement. Up and Down step between items; Home and End jump to the first and last. Only items that belong to this menu and are visible, enabled, focusable, and outside a hidden or inert subtree take part, so a disabled row is skipped rather than trapping focus.
  • Edge exit. Moving past the first or last item calls onDismissRequest with NAVIGATION.
  • Escape and Back. On the device, system Back traverses the temporary, same-URL history entry owned by the anchored-popup infrastructure and dismisses the menu before the previous application route can be reached. In desktop testing, Escape calls 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.
  • No handler, no capture. Without onDismissRequest the menu deliberately does not claim Back, desktop Escape, or edge navigation; the request keeps bubbling so something else can handle it.
  • Interception.onKeyDownCapture runs before the menu’s own handling for every key. If it calls preventDefault(), the menu leaves that key alone.
  • Materials. The surface uses the standard static material with a drop shadow, on a medium rounded-rectangle shape by default.

Accessibility

  • The popup root is a menu and is named Menu unless you pass aria-label. Give it a name that says what the commands act on.
  • The anchored-popup wrapper around the menu is a tooltip. Set tooltipContentDescription on the trigger so that wrapper is announced with the same meaning as the menu itself.
  • Each VerticalMenuButton is a menuitem named by its own text.
  • Disabled items stay visible and are skipped by arrow movement, which keeps an unavailable command discoverable without trapping focus on it.
  • Everything is reachable from the keyboard: Up, Down, Home, and End traverse, Enter and Space activate, and Escape tests the system Back dismissal path.
  • Keep the popup to about three priority commands with short, verb-led labels that fit within two lines.
  • Move a longer or explanatory command set to a dedicated route.
  • Spread getVerticalMenuAnchorProps(corner) last on the trigger so it is not overwritten by an earlier tooltip prop.
  • Close the menu synchronously on activation and restore trigger focus in a layout effect, before paint. Ordinary Back, Escape, or focus-navigation dismissal restores trigger focus through the popup infrastructure.
  • Verify the material and glow keep clearance from both display edges after focus expansion.

Avoid

  • Present the menu as a temporary popup. Inline or permanently visible commands belong in another navigation pattern.
  • Use a route-level navigation pattern for primary navigation. Menu items do not need navigation chevrons.
  • Use the menu’s component-owned surface without a nested scroller. A menu long enough to need scrolling belongs on its own route.
  • Supply onDismissRequest so Back and its desktop Escape equivalent can close the menu.
  • Stop item clicks from reaching the trigger. This fixes close-then-reopen flicker at its source instead of masking it with a timeout.