Add skidding or distance to customize menu offset position
EDITABLE EXAMPLE
<Menu>
<MenuButton>Select an option</MenuButton>
<MenuListskidding={20}distance={8}>
<MenuItem>List item</MenuItem>
<MenuItem>List item</MenuItem>
<MenuItem>List item</MenuItem>
</MenuList>
</Menu>
Accessibility
Keyboard Interaction
Key
Action
Enter or Space
When MenuButton receives focus, opens the menu and places focus on the first menu item
ArrowDown
When MenuButton receives focus, opens the menu and moves focus to the first menu item
ArrowUp
When MenuButton receives focus, opens the menu and moves focus to the last menu item
Escape
When 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
Name
Type
Default
Description
children
ReactNode
The children of the menu must be MenuButton or MenuList
isOpen
boolean
If true, the menu will be opened
autoSelect
boolean
false
The menu will select the first enabled item when it opens, the trigger item must be MenuButton
closeOnBlur
boolean
true
If true, the menu will close on outside click or blur
closeOnSelect
boolean
true
If true, the menu will close on menu item select
placement
PopperJS.placement
bottom-start
The 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
Name
Type
children
ReactNode
onClick
React.MouseEventHandler
onKeyDown
React.KeyboardEventHandler
MenuDivider
Name
Type
Default
Description
children
ReactNode
MenuGroup
Name
Type
Default
Description
children
ReactNode
The content of the menu group, should be the MenuItem component
title
string
The title of the menu group
MenuItem
Name
Type
Default
Description
disabled
boolean
If true, the menu item will be disabled
onClick
React.MouseEventHandler
Function that is called on click and enter/space keypress
onKeyDown
React.KeyboardEventHander
Function that is called on keydown
MenuList
Name
Type
Default
Description
children
ReactNode
The content of the MenuList, should be the MenuItem component
onClick
React.MouseEventHandler
Function to be called when you click on the menu item
onBlur
React.FocusEventHandler
Function to be called when you blur out of the menu list
skidding
number
0
Displaces the menu (in pixels) along the reference element. Used by popper.js
distance
number
0
Displaces the menu (in pixels) away from, or toward, the reference. Used by popper.js
MenuToggle
Name
Type
Default
Description
children
ReactNode | ({ getMenuToggleProps }) => ReactNode
disabled
boolean
Whether the menu toggle is disabled.
onClick
function
Callback when the menu toggle is clicked.
onKeyDown
function
Callback when the user presses a key.
MenuToggleIcon
Name
Type
Default
Description
appear
boolean
false
By default the child component does not perform the enter transition when it first mounts, regardless of the value of in. If you want this behavior, set both appear and in to true.
children
ReactNode | (state, props) => ReactNode
A function child can be used instead of a React element. This function is called with the current transition state ('entering', 'entered', 'exiting', 'exited'), ref, style, and context specific props for a component.
The timing function that describes how intermediate values are calculated during a transition. You may specify a single timing function for all transitions, or individually with an object.
in
boolean
If true, the component will transition in.
mountOnEnter
boolean
If true, it will "lazy mount" the component on the first in={true}. After the first enter transition the component will stay mounted, even on the 'exited' state, unless you also specify unmountOnExit. By default the child component is mounted immediately along with the parent transition component.
timeout
number | { appear?: number, enter?: number, exit?: number }
The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object.
unmountOnExit
boolean
If true, it will unmount the child component when in={false} and the animation has finished. By default the child component stays mounted after it reaches the 'exited' state.
Submenu
Name
Type
Default
Description
children
ReactNode
defaultIsOpen
boolean
false
Whether the submenu is open by default.
isOpen
boolean
Whether the submenu is open.
onClose
function
Callback when the submenu is closed.
onOpen
function
Callback when the submenu is opened.
placement
string
'right-start'
The placement of the submenu. One of: 'right-start', 'right-end', 'left-start', 'left-end'