How to show keyboard shortcuts alongside menu actions so people can discover and learn them.
A menu is where most people find out a shortcut exists. When an action in a DropdownMenu also has a keyboard shortcut, show the shortcut on the action — it teaches the shortcut in passing, without a separate reference to go looking for.
Put the shortcut in the item's elementAfter slot, using
KeyboardShortcut. The slot is pinned to the trailing edge of the
menu, so shortcuts line up down the whole menu no matter how long each label is, and menus across
different surfaces end up spaced the same way.
Let elementAfter do the alignment. It reserves the trailing edge and applies the gap, so every
item in the menu agrees without any per-item measuring.
Wrapping the label yourself puts the shortcut inside the label rather than in the item's trailing
slot. Each call site then picks its own gap, the spacing drifts between menus, and the shortcut no
longer aligns with a trailingIcon on a neighboring item.
Mod for the platform modifier. KeyboardShortcut renders it as ⌘ on macOS and Ctrl
elsewhere, so a single hotkey covers both.elementAfter
— the remaining shortcuts still line up. Never add a placeholder to fill the gap.shouldCloseOnClick={false}. One-shot actions should close as usual.elementBefore and elementAfter are the same pair of slots on
NavItem, Select options and the select
trigger, Button, Link and
TextField. Reach for them whenever something needs to sit at the leading
or trailing edge of a component, rather than composing it into the label.