Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. User Menu
  3. API and Development

User Menu

API and Development

View SourceOpens in a new tabSubmit IssueOpens in a new tab
Import UserMenu from @prepared911/ui/user-menu.
UserMenu
PropTypeDescription
nameLocalizedMessage | DisplayValueThe person's name: initials source, header title, and the visible name with showName
emailDisplayValueShown under the name in the header, truncated, full text as title
avatarSrcstringPhoto URL. Initials show without it or when it fails
initialsLocalizedMessage | DisplayValueAvatar text with no photo. Defaults to the first letters of the first two words of name
showNamebooleanDraw the name and a chevron from 640px up. Default false
triggerLabelLocalizedMessageAccessible name of the avatar trigger; required without trigger. Include the person's name
triggerReactElementA control that opens the menu in place of the avatar button, such as a preferences icon Button in a top bar. It keeps its own name; UserMenu adds aria-haspopup, aria-expanded, the press and arrow-key handlers and focus return. With it, triggerLabel, showName, disabled, className and ref are not accepted (put them on the control)
itemsreadonly UserMenuItem[]Optional slot for extra account actions, off by default. Rows sit just before Sign out; a press runs onSelect and closes the menu
appearanceSectionLabelLocalizedMessageHeading of the Appearance section (Theme, Reduce motion, Reset layout, Zoom). Without it the rows have no heading
soundSectionLabelLocalizedMessageHeading of the Sound section (Headset volume, Application sound). Without it the rows have no heading
appearanceLabelsUserMenuAppearanceLabelsPassing it shows the Theme row
appearance / defaultAppearance / onAppearanceChangeAppearanceModeControlled value, initial value (default System), and the report
reduceMotionLabelLocalizedMessagePassing it shows the Reduce motion row
reduceMotion / defaultReduceMotion / onReduceMotionChangebooleanControlled value, initial value (default false), and the report
onResetLayout() => voidPassing it shows the Reset layout row in Appearance, after Reduce motion. The menu stays open; the host confirms or offers undo (destructive-action-has-confirmation-or-undo)
resetLayoutLabelLocalizedMessageRow label, and the row's accessible name. Defaults to USER_MENU_DEFAULT_RESET_LAYOUT_LABEL ("Reset layout")
resetLayoutButtonLabelLocalizedMessageVisible text of the row's outlined chip, which is decorative. Defaults to USER_MENU_DEFAULT_RESET_LAYOUT_BUTTON_LABEL ("Reset")
showZoombooleanWhen true, the Zoom row may render if its label, value and handler are set. Default false. The shell sets this (the web app leaves it off); UserMenu does not read the user agent
zoomLabelLocalizedMessageLabel of the Zoom row. With showZoom true, shows the row when paired with zoom and onZoomChange
zoom / onZoomChangenumber, handlerControlled zoom in percent (80–150). onZoomChange is required when zoom is set
headsetVolumeLabelLocalizedMessageLabel of the Headset volume row. Shows the row when paired with headsetVolume and onHeadsetVolumeChange
headsetVolume / onHeadsetVolumeChangenumber, handlerControlled level from 1 to 15
applicationSoundLabelLocalizedMessageLabel of the Application sound row. Shows the row when paired with applicationSound and onApplicationSoundChange
applicationSound / onApplicationSoundChangenumber, handlerControlled level from 0 to 15
signOutLabel, signingOutLabelLocalizedMessageSign out row label, and its label while pending. The row is neutral, not destructive
onSignOut() => void | Promise<void>A promise keeps the menu open on a busy row until it settles
open / defaultOpen / onOpenChangeboolean, (open, details) => voidOpen state
sideSideDefault "block-end"
alignAlignDefault "end"
disabledbooleanInert trigger
classNamestringAppended to the trigger
refRef<HTMLButtonElement>The trigger
UserMenuItem
FieldTypeDescription
idstringUnique among the items
labelLocalizedMessage | DisplayValueRow label
iconGlyphOptional leading icon
disabledbooleanInert row
onSelect() => voidCalled on a press; the menu then closes and focus returns to the trigger
Constants
Exported from @prepared911/ui/user-menu: USER_MENU_ZOOM_MIN (80), USER_MENU_ZOOM_MAX (150), USER_MENU_HEADSET_VOLUME_MIN (1), USER_MENU_HEADSET_VOLUME_MAX (15), USER_MENU_APPLICATION_SOUND_MIN (0), USER_MENU_APPLICATION_SOUND_MAX (15), USER_MENU_PREFERENCE_SLIDER_STEP (1), USER_MENU_DEFAULT_RESET_LAYOUT_LABEL and USER_MENU_DEFAULT_RESET_LAYOUT_BUTTON_LABEL.
Enums
  • AppearanceMode: Light, Dark, System.
Props
NameTypeDefaultDescription
nameUserMenuName—The person's name. It is the avatar's initials source and the header title. Empty shows a skeleton line.
onSignOut() => void | Promise<void>—Called when a person presses Sign out. When it returns a promise the row shows a spinner, reads signingOutLabel, is aria-busy, and ignores further presses until the promise settles; then the menu closes. A rejection is left to the app and still closes the menu.
signingOutLabelLocalizedMessage—Label of the sign out row while onSignOut is pending.
signOutLabelLocalizedMessage—Label of the sign out row.
alignAlign"end"Alignment along that edge.
appearanceAppearanceMode—Controlled appearance preference. Pair with onAppearanceChange.
appearanceLabelsUserMenuAppearanceLabels—Names of the appearance choices. Passing it shows the Theme row.
appearanceSectionLabelLocalizedMessage—Visible heading of the Appearance section: Theme, Reduce motion, Reset layout and Zoom. Without it those rows sit in the menu with no heading.
applicationSoundnumber—Controlled application sound level from 0 to 15. Pair with onApplicationSoundChange.
applicationSoundLabelLocalizedMessage—Label of the Application sound row. Shows the row when paired with applicationSound and onApplicationSoundChange.
avatarSrcstring—Trusted image URL of the person's photo. Without it, or when it fails to load, the initials show.
classNamestring—@deprecated Pass layout through enum props and shipped parts. Request a missing case via find-pattern.
defaultAppearanceAppearanceModeAppearanceMode.SystemInitial appearance preference when uncontrolled.
defaultOpenbooleanfalseInitial open state when uncontrolled.
defaultReduceMotionbooleanfalseInitial reduce motion preference when uncontrolled.
disabledboolean—Disables the trigger.
emailDisplayValue—The person's email. It is truncated in the header and its full text is the title. Empty shows a skeleton line.
headsetVolumenumber—Controlled headset volume from 1 to 15. Pair with onHeadsetVolumeChange.
headsetVolumeLabelLocalizedMessage—Label of the Headset volume row. Shows the row when paired with headsetVolume and onHeadsetVolumeChange.
initialsUserMenuName—Text shown when there is no photo. Defaults to the first letters of the first two words of name.
itemsreadonly UserMenuItem[]—Extra account actions, drawn as rows after the rule below the preferences and before Sign out. Off by default: with none the menu is the design's menu. Pass only actions the person can take from the account menu, such as Diagnostics for a super admin.
onAppearanceChangeAppearanceChangeHandler—Called when a person picks an appearance. UserMenu only reports; the app applies it, for example by setting data-theme on <html>. The menu stays open. May be canceled.
onApplicationSoundChangeApplicationSoundChangeHandler—Called when the application sound slider changes. May be canceled.
onHeadsetVolumeChangeHeadsetVolumeChangeHandler—Called when the headset volume slider changes. May be canceled.
onOpenChangeUserMenuOpenChangeHandler—Called on trigger press ("trigger-press"), item press ("item-press"), Tab ("focus-out"), and Escape or an outside press ("light-dismiss", not cancelable).
onReduceMotionChangeReduceMotionChangeHandler—Called when a person flips the switch. UserMenu only reports; the app applies it by setting data-motion="reduced" on <html>. The menu stays open. May be canceled.
onResetLayout(() => void)—Called when the person presses the Reset layout row in the Appearance section. The row renders only when this callback is set. UserMenu does not confirm: the host implements confirmation or undo before applying the reset (destructive-action-has-confirmation-or-undo). The menu stays open.
onZoomChangeZoomChangeHandler—Called when the zoom slider changes. May be canceled.
openboolean—Controlled open state. Pair with onOpenChange.
reduceMotionboolean—Controlled reduce motion preference. Pair with onReduceMotionChange.
reduceMotionLabelLocalizedMessage—Label of the Reduce motion switch row. Passing it shows the row.
refRef<HTMLButtonElement>—Ref to the trigger button.
resetLayoutButtonLabelLocalizedMessage{@link USER_MENU_DEFAULT_RESET_LAYOUT_BUTTON_LABEL }Visible text of the outlined chip at the inline end of the Reset layout row. The chip is decorative: the row is the control.
resetLayoutLabelLocalizedMessage{@link USER_MENU_DEFAULT_RESET_LAYOUT_LABEL }Label of the Reset layout row, at its inline start. It is also the row's accessible name.
showNamebooleanfalseShows the name and a chevron beside the avatar from 640px of viewport width up. Below that only the avatar shows.
showZoombooleanfalseWhen true, the Zoom preference row may render if its label, value and handler are set. The shell sets this; UserMenu does not read the user agent.
sideSide"block-end"Preferred edge of the trigger.
soundSectionLabelLocalizedMessage—Visible heading of the Sound section: Headset volume and Application sound. Without it those rows sit in the menu with no heading.
triggerReactElement<MenuControlChildProps, string | JSXElementConstructor<any>>—A control that opens the menu in place of the avatar button; see {@link UserMenuCustomTriggerProps}. The control that opens the menu, usually a Button. UserMenu adds aria-haspopup="menu", aria-expanded, the press and arrow-key handlers and, on close, returns focus to it; the control's own handlers run first and its ref is kept. Name it with its own label, and set disabled, className and ref on it, not on UserMenu.
triggerLabel(string & { readonly [LOCALIZED_MESSAGE_BRAND]: true; })—Name of the avatar trigger. Required with it; see {@link UserMenuAvatarTriggerProps}. Accessible name of the avatar trigger, such as "Dana Levi, account menu". It includes the person's name.
zoomnumber—Controlled zoom level in percent, from 80 to 150.
zoomLabelLocalizedMessage—Label of the Zoom row. With {@link UserMenuBaseProps.showZoom} true, shows the row when paired with zoom and onZoomChange.
Storybook
Interactive examples and edge cases for this component are in Storybook.
DefaultOpens in a new tab
Previous
User Menu / Usage
Next
User Menu / Accessibility
On this page
UserMenu
UserMenuItem
Constants
Enums
Props
Storybook