Menu Item
- Stable
- WCAG 2.2 evidence
- RTL
- Web · iOS · Android
One action or option in a Menu or ContextMenu.
Built on React Aria MenuItem: role menuitem (menuitemcheckbox / menuitemradio when the menu has a
selectionMode), arrow keys, Home/End and type-ahead move focus, Enter and Space activate, disabled items are skipped
(WCAG 2.1.1, 4.1.2). Keyboard focus shows the focus ring (2.4.7). Selection is owned by the menu (selectedKeys). Consumer duties: item wording, and registering any shortcut you display.
import { MenuItem } from "@nexera-ui/react";- 4
- examples
- 28
- props
- 4
- live controls
- 3
- platforms
- 10
- WCAG criteria
- 7
- blocks use it
Try every prop. Copy the code.
Change the props and the code updates. Check light and dark, LTR and RTL, and phone width.
import { MenuItem } from "@nexera-ui/react";
<MenuItem />Examples 3
The same examples as Storybook, rendered live. Open Code to copy one.
Types
Every Figma Type in context. selectable comes from the menu's selectionMode, submenu from SubmenuTrigger.
import { type ReactNode } from "react";
import { AriaMenu, type AriaMenuProps } from "react-aria-components";
import {
MenuDivider,
MenuItem,
menuListStyles,
menuPopoverStyles,
usePlatform,
} from "@nexera-ui/react";
import { LuCopy, LuPencil, LuShare2, LuTrash2 } from "react-icons/lu";
function StaticMenu({
platform: platformProp,
children,
...props
}: { platform?: Platform | undefined; children: ReactNode } & Omit<
AriaMenuProps<object>,
"children"
>) {
const platform = usePlatform(platformProp);
return (
<div data-platform={platform} className={menuPopoverStyles({ platform })}>
<MenuPlatformContext.Provider value={platform}>
<AriaMenu className={menuListStyles({ platform })} {...props}>
{children}
</AriaMenu>
</MenuPlatformContext.Provider>
</div>
);
}
export function Types() {
return (
<div className="flex flex-wrap items-start gap-6">
<StaticMenu aria-label="File">
<MenuItem id="edit" label="Edit" icon={<LuPencil />} shortcut="E" />
<MenuItem
id="copy"
label="Duplicate"
icon={<LuCopy />}
description="Changes are saved instantly"
/>
<MenuItem id="share" label="Share" icon={<LuShare2 />} type="submenu" />
<MenuItem id="move" label="Move" isDisabled />
<MenuDivider />
<MenuItem id="delete" label="Delete" type="destructive" icon={<LuTrash2 />} />
</StaticMenu>
<StaticMenu aria-label="View" selectionMode="multiple" defaultSelectedKeys={["grid"]}>
<MenuItem id="grid" label="Show grid" />
<MenuItem id="rulers" label="Show rulers" />
<MenuItem id="guides" label="Show guides" />
</StaticMenu>
</div>
);
}
Platforms
Figma System menu item: platform="ios" (44 pt rows, 18 pt icon after the label) and platform="android" (48 dp, 24 dp icon).
import { type ReactNode } from "react";
import { AriaMenu, type AriaMenuProps } from "react-aria-components";
import { MenuItem, menuListStyles, menuPopoverStyles, usePlatform } from "@nexera-ui/react";
import { LuCopy, LuShare2, LuTrash2 } from "react-icons/lu";
const platforms = ["web", "ios", "android"] as const;
function StaticMenu({
platform: platformProp,
children,
...props
}: { platform?: Platform | undefined; children: ReactNode } & Omit<
AriaMenuProps<object>,
"children"
>) {
const platform = usePlatform(platformProp);
return (
<div data-platform={platform} className={menuPopoverStyles({ platform })}>
<MenuPlatformContext.Provider value={platform}>
<AriaMenu className={menuListStyles({ platform })} {...props}>
{children}
</AriaMenu>
</MenuPlatformContext.Provider>
</div>
);
}
export function Platforms() {
return (
<div className="flex flex-wrap items-start gap-6">
{platforms.map((platform) => (
<div key={platform} className="flex flex-col gap-2">
<span className="text-body-caption text-secondary">{platform}</span>
<StaticMenu aria-label={`Share (${platform})`} platform={platform}>
<MenuItem id="share" label="Share" icon={<LuShare2 />} />
<MenuItem id="copy" label="Copy" icon={<LuCopy />} />
<MenuItem id="delete" label="Delete" type="destructive" icon={<LuTrash2 />} />
</StaticMenu>
</div>
))}
</div>
);
}
Long label
Labels and descriptions wrap instead of truncating (translation can add 30 to 40 %).
import { type ReactNode } from "react";
import { AriaMenu, type AriaMenuProps } from "react-aria-components";
import { MenuItem, menuListStyles, menuPopoverStyles, usePlatform } from "@nexera-ui/react";
import { LuShare2 } from "react-icons/lu";
function StaticMenu({
platform: platformProp,
children,
...props
}: { platform?: Platform | undefined; children: ReactNode } & Omit<
AriaMenuProps<object>,
"children"
>) {
const platform = usePlatform(platformProp);
return (
<div data-platform={platform} className={menuPopoverStyles({ platform })}>
<MenuPlatformContext.Provider value={platform}>
<AriaMenu className={menuListStyles({ platform })} {...props}>
{children}
</AriaMenu>
</MenuPlatformContext.Provider>
</div>
);
}
export function LongLabel() {
return (
<StaticMenu aria-label="Move">
<MenuItem
id="archive"
label="Move to the archived projects folder of the previous financial year"
description="Everyone with access to the folder can see it"
icon={<LuShare2 />}
shortcut="⌘⇧M"
/>
</StaticMenu>
);
}
Props 28
Press "Try it" on a card to load that prop into the playground.
28 props shown
label*NexeraReactNodeVisible label. Start with a verb ("Edit", "Move to folder"). It names the item and wraps
instead of truncating. When it is not a plain string, also pass textValue so type-ahead can find the item.
descriptionNexeraReactNodeSecondary line under the label. Linked with aria-describedby.
iconNexeraReactNodeIcon. Decorative: the label names the item. Shown before the label on web and after it on iOS and Android.
shortcutNexerastringKeyboard shortcut hint, for example "⌘E" or "Ctrl+E". Rendered as <kbd>,
kept left-to-right and announced as the item's description. It is a hint only: register the shortcut yourself.
typeNexera"action" | "destructive" | "selectable" | "submenu"Item type. destructive uses the danger colour; the label must still say what happens ("Delete
file"), because colour alone is not enough (WCAG 1.4.1). selectable shows the check slot and submenu the
chevron; both are inferred when omitted, from the menu's selectionMode and from SubmenuTrigger.
platformNexera"web" | "ios" | "android"Platform look. Defaults to the
platform of the enclosing Menu, then of the NexeraProvider.
classNameNexerastringExtra classes, merged last so they win over the defaults.
styleNexeraCSSPropertiesInline style.
idReact AriaKeyThe unique id of the item.
valueReact AriaTThe object value that this item represents. When using dynamic collections, this is set automatically.
textValueReact AriastringA string representation of the item's contents, used for features like typeahead.
aria-labelReact AriastringAn accessibility label for this item.
isDisabledReact AriabooleanWhether the item is disabled.
onActionReact Aria() => voidHandler that is called when the item is selected.
shouldCloseOnSelectReact AriabooleanWhether the menu should close when the menu item is selected.
hrefReact AriastringA URL to link to. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href).
hrefLangReact AriastringHints at the human language of the linked URL. See[MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#hreflang).
targetReact AriaHTMLAttributeAnchorTargetThe target window for the link. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target).
relReact AriastringThe relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel).
downloadReact Ariastring | booleanCauses the browser to download the linked URL. A string may be provided to suggest a file name. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download).
pingReact AriastringA space-separated list of URLs to ping when the link is followed. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#ping).
referrerPolicyReact Aria"" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url"How much of the referrer to send when following the link. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#referrerpolicy).
routerOptionsReact ArianeverOptions for the configured client side router.
onPressReact Aria(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStartReact Aria(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEndReact Aria(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChangeReact Aria(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUpReact Aria(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
* Required. React Aria props shown are the ones most apps use; the component accepts the rest of its React Aria props too.
Accessible by default.
Built on React Aria, and covered by the WCAG 2.2 evidence generated on every build.
WCAG 2.2 evidence
4 direct · 6 supporting- 1.3.1Info and RelationshipsLevel A · tested directly
- 1.4.1Use of ColorLevel A · supporting test
- 1.4.10ReflowLevel AA · supporting test
- 1.4.11Non-text ContrastLevel AA · supporting test
- 1.4.12Text SpacingLevel AA · supporting test
- 2.1.1KeyboardLevel A · tested directly
- 2.4.7Focus VisibleLevel AA · tested directly
- 2.4.11Focus Not Obscured (Minimum)Level AA · supporting test
- 2.5.8Target Size (Minimum)Level AA · supporting test
- 4.1.2Name, Role, ValueLevel A · tested directly
Fits any width.
Nexera components respond to the space they are given. Drag the corner of the frame, or pick a width.
Styling hooks
Pass className to add Tailwind classes (merged last). State is exposed as data attributes, so you can style it with variants like data-pressed:.
data-disableddata-hovereddata-opendata-pressed
<MenuItem className="data-disabled:opacity-90 shadow-sm" />Used in blocks
- Sidebar app shellApp shells and navigation
- Page headerApp shells and navigation
- Workspace switcherApp shells and navigation
- Filter barLists, tables and records
- File browserLists, tables and records
- ChatMessaging and collaboration
- Helpdesk assistantMessaging and collaboration
Related components
- BoardCardA Kanban card: avatar, name, role, drag handle and a detail line.
- ButtonTriggers an action such as Save, Submit, Approve or Delete.
- ButtonGroupItemOne toggle in a joined row of buttons, for example a List / Grid view switch or a set of filters.
- ContextMenuThe menu of actions for an element, opened where the user asks for it: right-click, long-press on touch screens, and from the keyboard with Shift+F10 or the ContextMenu key (the browser reports both as a `contextmenu` event on the focused element; on macOS, Control+Enter).
- DragHandleGrip that starts a drag of the collection item it sits in.
- DropIndicatorInsertion line shown between two items while something is dragged over a `GridList` or `ListBox`.
- IconButtonA square, icon-only button for compact actions such as Settings, Close or Delete row.
- MenuA list of actions or options that opens from a trigger.