Components · engine.menu · version 0.1.0
Menu
A button that opens a list of commands. Pressing an item runs its command; a menu holds no value.
Preview
Every variant in every state, drawn by the same definition that the Figma sync and the tests use.
| Component | rest | open |
|---|---|---|
| menu |
Install
npm install @uiuxengine/reactComponents come from npm and stay identical to their definition and their Figma component. See Installation.
Usage
import { Menu } from "@uiuxengine/react";
export function Example() {
return (
<Menu label="Actions" />
);
}Guidelines
- Use for commands, for example 'Duplicate' or 'Archive'. Links that navigate, such as site navigation, belong in a navigation list, not a menu.
- The trigger's label names the group of commands, for example 'Actions'. An icon-only trigger needs an accessibleLabel.
- Keep menus short and flat. Put the commands people use most first.
- A command that needs confirmation or more input opens a dialog from itemPress. The menu has closed and focus is on its trigger by then.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "primary" | "secondary" | "ghost" | "danger" | secondary | The trigger's visual emphasis. |
size | "sm" | "md" | "lg" | md | The trigger's size within the current density. |
label | text, up to 80 | — | The trigger's visible text. |
accessibleLabel | text, up to 160 | — | The trigger's accessible name when it has no visible label. |
disabled | boolean | false | Prevents opening the menu. |
Slots
| Slot | Takes | Description |
|---|---|---|
icon | icon | Icon before the trigger's label. |
items | list of engine.menu-item | The commands, in order. |
Events
itemPress- A person or an authorized agent pressed an enabled item. The menu then asks to close.
openChange- The menu was opened or closed.
Accessibility
- Renders a native <div> with the role
generic. - A menu needs a label or an accessibleLabel.
- A menu's trigger needs a label or an icon.
As a spec
Agents describe interfaces as JSON specs. A spec renders only after it validates against the installed contracts, the approved icons and the host's actions. Edit it to see.
No actions yet.
JSON Schema of the props
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "urn:uiuxengine:component:engine.menu@0.1.0",
"title": "menu",
"description": "A button that opens a list of commands. Pressing an item runs its command; a menu holds no value.",
"type": "object",
"properties": {
"variant": {
"description": "The trigger's visual emphasis.",
"type": "string",
"enum": [
"primary",
"secondary",
"ghost",
"danger"
],
"default": "secondary"
},
"size": {
"description": "The trigger's size within the current density.",
"type": "string",
"enum": [
"sm",
"md",
"lg"
],
"default": "md"
},
"label": {
"description": "The trigger's visible text.",
"type": "string",
"maxLength": 80
},
"accessibleLabel": {
"description": "The trigger's accessible name when it has no visible label.",
"type": "string",
"maxLength": 160
},
"disabled": {
"description": "Prevents opening the menu.",
"type": "boolean",
"default": false
},
"icon": {
"$ref": "#/$defs/iconRef",
"description": "Icon before the trigger's label."
},
"items": {
"description": "The commands, in order.",
"type": "array",
"items": {
"type": "object",
"properties": {
"component": {
"enum": [
"engine.menu-item"
]
},
"props": {
"type": "object"
}
},
"required": [
"component"
],
"additionalProperties": false
},
"minItems": 1
}
},
"required": [
"items"
],
"additionalProperties": false,
"allOf": [
{
"anyOf": [
{
"required": [
"label"
]
},
{
"required": [
"accessibleLabel"
]
}
]
},
{
"anyOf": [
{
"required": [
"label"
]
},
{
"required": [
"icon"
]
}
]
}
],
"$defs": {
"iconRef": {
"type": "object",
"description": "A reference to an icon in the host's approved catalog.",
"properties": {
"type": {
"const": "icon"
},
"id": {
"type": "string",
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
},
"style": {
"type": "string",
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
},
"weight": {
"type": "string",
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
}
},
"required": [
"type",
"id"
],
"additionalProperties": false
}
}
}