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.

menu in every variant and state
Componentrestopen
menu

Install

npm install @uiuxengine/react

Components 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

PropTypeDefaultDescription
variant"primary" | "secondary" | "ghost" | "danger"secondaryThe trigger's visual emphasis.
size"sm" | "md" | "lg"mdThe trigger's size within the current density.
labeltext, up to 80—The trigger's visible text.
accessibleLabeltext, up to 160—The trigger's accessible name when it has no visible label.
disabledbooleanfalsePrevents opening the menu.

Slots

SlotTakesDescription
iconiconIcon before the trigger's label.
itemslist of engine.menu-itemThe 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
    }
  }
}