Menu
What is this?β
Menu triggers allow merchants to open a dropdown and start contextual actions that are rarely used or repeated for each item in a list.
Compositionβ
Name | Description |
---|---|
MenuButton | Button that triggers the menu popover |
Menu | Menu's popover |
MenuItem | Represents a button rendered inside the MenuList |
MenuDivider | Represents an hr used to separate the menu popover into sections |
Variantsβ
MenuButton has four possible variants: primary
, secondary
, tertiary
and neutralTertiary
. Primary is the default variant.
Sizesβ
MenuButton has two possible sizes: normal
and large
. Normal is the default size.
Icon onlyβ
You can use the labelHidden
property to hide the MenuButton label
Customβ
It possible to use the label
MenuButton property to set the button text. When a custom label is used, the icon changes to the IconCaretDown/Up.
Disabledβ
Disable the MenuButton by setting the disabled
property to true.
Bleedβ
MenuButton can trespass the parent padding for some alignment and layout reasons, it is possible to achieve this behavior through the bleedX
and bleedY
property.
Itemβ
MenuItem has two possible variants: neutral and critical, to enable the critical variant, the critical
property needs to be true.
Item clickβ
It is possible to set a custom action when a item is clicked.
Item disabledβ
Disable the MenuItem by setting the disabled
property to true.
Usageβ
import {
MenuButton,
Menu,
MenuItem,
MenuDivider,
useMenuState,
} from '@vtex/admin-ui'
function Example() {
const state = useMenuState()
return (
<>
<MenuButton state={state} />
<Menu state={state}>
<MenuItem label="Create" icon={<IconPlus />} />
<MenuItem label="Edit" icon={<IconPencil />} />
<MenuItem label="Download" icon={<IconArrowLineDown />} />
</Menu>
</>
)
}
MenuButton Propsβ
Name | Type | Description | Required | Default |
---|---|---|---|---|
state | MenuStateReturn | useMenuState hook return | β | - |
size | normal, large | Button size | π« | normal |
variant | primary, secondary, tertiary, neutralTertiary | Button variant | π« | primary |
label | string | Button label | π« | More actions |
labelHidden | boolean | Whether the label is visible or not | π« | false |
bleedX | boolean | Whether the Button should trespass the parent paddingX | π« | false |
bleedY | booelean | Whether the Button should trespass the parent paddingY | π« | false |
Menu Propsβ
Name | Type | Description | Required | Default |
---|---|---|---|---|
state | MenuStateReturn | useMenuState hook return | β | - |
MenuItem Propsβ
Name | Type | Description | Required | Default |
---|---|---|---|---|
label | string | Item label | β | - |
icon | ReactNode | Item icon | π« | - |
critical | boolean | Whether the item variant is critical | π« | false |
Accessibilityβ
Menu
has rolemenu
.MenuItem
has rolemenuitem
.- Pressing Enter on
MenuButton
opens theMenu
and places focus on its first item. - When
MenuItem
has focus, Space and Enter triggers it.
Best Practicesβ
You must always set the aria-label
property in the Menu
component.
function Example() {
const state = useMenuState()
return (
<>
<MenuButton state={state} />
<Menu aria-label="actions" state={state}>
<MenuItem label="Create" icon={<IconPlus />} />
<MenuItem label="Edit" icon={<IconPencil />} />
<MenuItem label="Download" icon={<IconArrowLineDown />} />
<MenuDivider />
<MenuItem label="Delete" icon={<IconTrash />} critical />
</Menu>
</>
)
}
Keyboard Navigationβ
- β moves focus to the next `MenuItem`.
- β moves focus to the previous `MenuItem`.
Componentsβ
When to use the Tab, the Button, or a group of Buttons instead of the Menu?
- Choose the Tab component for navigation triggers that alternate between related views within the same container.
- Choose the Button when there is only one action trigger.
- Choose a group of Buttons when the group will not be repeated in a list and all its actions are frequently used.
Variantsβ
When should a Menu be primary, secondary, or tertiary?
- When the most frequent action of the page leads to a menu with complementary options, use a primary Menu. For example, a Menu with the Create page label that leads to options such as Landing page and Category page.
- There should be only one primary action visible at a time.
- A Menu should never be secondary.
When should a Menu be neutral tertiary?
- When the same Menu is repeated, such as for each list item.
- When there is a group of tertiary Buttons and a Menu, they all should be neutral.
- When the container background uses the
$bg.secondary
color.
When should a Menu Item be critical?
Donβt use critical colors for Move to trash triggers that imply the possibility of reverting the action.
What should be the Menuβs size?
Where should an icon be positioned in a Menu?
- When using the default More actions label, position the icon to the left.
- When using a custom label, position the icon to the right.
Positionβ
When should I use more than one Menu?
Don't use more than one Menu in the same container.
Where should the Menu be positioned in a container?
- Align the Menu to the right. For example, a Menu in the header of a Card should be vertically-centered and aligned to the right.
- In a group of actions, position the Menu as the last action.
- When a tertiary Menu is next to other content, ignore the Menu's box to align based on the Menu's icon and/or label. Use the bleed prop to implement this alignment.
Behaviorβ
When to use a disabled Menu?
When to use a disabled Menu Item?
- Use a disabled Menu Item only if, in some condition, it becomes enabled. For example, a Publish button that is only enabled when edits have been made.
- When the reason why an action is disabled might be unclear, leave the action enabled and show a modal explaining the reason on trigger.
- Don't display a Tooltip when hovering a disabled Menu Item.
Contentβ
What should be the label of a Menu?
When writing a custom label, consider the following recommendations:
- Reuse existing labels.
- Always include a verb in the infinitive and an object. For example, Create product.
- Use a verb that reflects the exact action that the Menu triggers for every Menu Item. For example, use the label Create promotion for a Menu where the items are the different promotion types that can be created.
- Use sentence case but capitalize proper nouns.
- Donβt use punctuation.
- Donβt use more than three words.
- Donβt use personal pronouns.
What should be the label of a Menu?
- Reuse existing labels.
- Always include a verb in the infinitive, except for when the Menu Item is inside a Menu with a custom label where the action is already defined in the Menu label.
- When the context already has a label for the object, remove the object from the label. For example, use Edit instead of Edit product.
- Leave the object explicit when the Menu has the same action for different objects, such as Edit product and Edit SKUs.
- Use a verb that reflects the exact action that the Menu Item triggers. For example, use Rename instead of Change name.
- Use sentence case but capitalize proper nouns.
- Donβt use punctuation.
- Donβt use more than three words.
- Donβt use personal pronouns.
When should I hide Menu Items icons?
When should a Menu have a hidden label and only an icon visible?
- Don't hide the label of a Menu with a custom label.
- Donβt use a Tooltip to display the label.