Tonic UI
Getting StartedColor ModeColor StyleContributing
THEME
BordersBreakpointsColorsOutlinesPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Menu

An accessible dropdown menu for the common dropdown menu button design pattern. Menu uses roving tabIndex for focus management.

Import

  • Menu: The wrapper component that provides context, state, and focus management.
  • MenuList: The wrapper for the menu items. Must be a direct child of Menu.
  • MenuItem: The trigger that handles menu selection. Must be a direct child of a MenuList.
  • MenuGroup: A wrapper to group related menu items.
  • MenuDivider: A visual separator for menu items and groups.
  • MenuButton: The trigger for the menu list. Must be a direct child of Menu.

Usage

Basic menu with an anchor

EDITABLE EXAMPLE

Basic menu with MenuButton

EDITABLE EXAMPLE

Group

EDITABLE EXAMPLE

Divider

EDITABLE EXAMPLE

Disabled

Add disabled property on MenuItem

EDITABLE EXAMPLE

Set the minimum width of the MenuList to the width of the MenuButton

EDITABLE EXAMPLE

Menu with icon

EDITABLE EXAMPLE

Dropup Menu

Add the placement property with top-start

EDITABLE EXAMPLE

Menu with checkbox

Need to set closeOnSelect to false on Menu

EDITABLE EXAMPLE

Menu with label inline

EDITABLE EXAMPLE

Offset position

Add skidding or distance to customize menu offset position

EDITABLE EXAMPLE

Accessibility

Keyboard Interaction

KeyAction
Enter or SpaceWhen MenuButton receives focus, opens the menu and places focus on the first menu item
ArrowDownWhen MenuButton receives focus, opens the menu and moves focus to the first menu item
ArrowUpWhen MenuButton receives focus, opens the menu and moves focus to the last menu item
EscapeWhen the menu is open, closes the menu and sets focus to the MenuButton

ARIA roles

For MenuButton:

  • It has role set to button.
  • It has aria-haspopup set to either menu.
  • When the menu is displayed, MenuButton has aria-expanded set to true.
  • MenuButton has aria-controls set to the id of the MenuList.

For MenuList:

  • It contains the MenuItem has role menu.

Props

Menu

NameTypeDefaultDescription
childrenReactNodeThe children of the menu must be MenuButton or MenuList
isOpenbooleanIf true, the menu will be opened
autoSelectbooleanfalseThe menu will select the first enabled item when it opens, the trigger item must be MenuButton
closeOnBlurbooleantrueIf true, the menu will close on outside click or blur
closeOnSelectbooleantrueIf true, the menu will close on menu item select
placementPopperJS.placementbottom-startThe placement of the MenuList. One of: 'top', 'bottom', 'right', 'left', 'top-start', 'top-end', 'bottom-start', 'bottom-end', 'right-start', 'right-end', 'left-start', 'left-end'

MenuButton

NameType
childrenReactNode
onClickReact.MouseEventHandler
onKeyDownReact.KeyboardEventHandler

MenuList

NameTypeDefaultDescription
childrenReactNodeThe content of the MenuList, should be the MenuItem component
onClickReact.MouseEventHandlerFunction to be called when you click on the menu item
onBlurReact.FocusEventHandlerFunction to be called when you blur out of the menu list
skiddingnumber0Displaces the menu (in pixels) along the reference element. Used by popper.js
distancenumber0Displaces the menu (in pixels) away from, or toward, the reference. Used by popper.js

MenuItem

NameTypeDefaultDescription
disabledbooleanIf true, the menu item will be disabled
onClickReact.MouseEventHandlerFunction that is called on click and enter/space keypress
onKeyDownReact.KeyboardEventHanderFunction that is called on keydown

MenuGroup

NameTypeDefaultDescription
childrenReactNodeThe content of the menu group, should be the MenuItem component
titlestringThe title of the menu group