Skip to Content
Cristal

Actions

Menu

A list of actions opened from a button.

<cr-menu>CrMenu

Example

Actions are written as child <option> elements, as in the select. The onCrSelect event gives the value of the chosen action in event.detail.

'use client';

import { useState } from 'react';
import { CrMenu } from '@cristal-ui/react';

export default function MenuActions() {
  const [action, setAction] = useState('');

  return (
    <>
      <CrMenu label="Actions" animation="anchor-pop" onCrSelect={(event) => setAction(event.detail)}>
        <option value="edit">Edit</option>
        <option value="duplicate">Duplicate</option>
        <option value="archive" disabled>
          Archive
        </option>
        <option value="delete">Delete</option>
      </CrMenu>
      <span role="status">{action && `Selected action: ${action}`}</span>
    </>
  );
}

Animations

The animation property picks the opening and closing effect. It is also available on the select. Open each menu to compare.

ValueEffect
fadesubtle fade (default)
anchor-popthe menu springs out of the button with a slight bounce, and shrinks back into it on selection
turn-overthe panel flips over like a card
card-dealthe actions are dealt like cards; the chosen one flies back to the button
drum-rollthe actions roll in on a drum, then roll away downwards
outline-tracea purple → cyan outline draws the panel, then the items sweep in
tile-buildthe panel builds up in waves of tiles, then bursts apart
import { CrMenu } from '@cristal-ui/react';

const animations = ['fade', 'anchor-pop', 'turn-over', 'card-deal', 'drum-roll', 'outline-trace', 'tile-build'] as const;

export default function MenuAnimations() {
  return (
    <>
      {animations.map((animation) => (
        <CrMenu key={animation} label={animation} animation={animation}>
          <option value="list">List</option>
          <option value="grid">Grid</option>
          <option value="board">Board</option>
          <option value="calendar">Calendar</option>
        </CrMenu>
      ))}
    </>
  );
}

If the user has asked their system to reduce motion, every animation becomes a simple fade. Animations last less than half a second and never block keyboard use.

Keyboard

KeyButtonOpen menu
Enter, Space, Down Arrowopens the menu on the first actionselects the action
Up Arrowopens the menu on the last actionprevious action
Down Arrow—next action
Home / End—first / last action
Letters—moves to the action starting with those letters
Escape—closes and returns focus to the button
Tab—closes and moves to the next element

Accessibility

  • Follows the W3C "menu button" pattern (ARIA Authoring Practices): aria-haspopup="menu", aria-expanded, menu and menuitem roles.
  • Focus moves into the menu when it opens and returns to the button after a selection or Escape.
  • Unavailable actions (disabled) are announced and skipped by navigation.
  • When several menus share the same label (an "Actions" menu on each table row), give each one a specific name with accessibleLabel: "Actions for Keyboard", "Actions for Mouse"… This name must contain the visible label (WCAG 2.5.3), so that people who control their computer by voice can say "Actions".
  • The menu is displayed above the page: it is never clipped by a container or a dialog, and it opens upwards when space runs out. Inside a dialog, Escape closes the menu without closing the dialog.

API

Properties

PropertyTypeDefaultDescription
accessibleLabelstring—Nom complet annoncé par les lecteurs d'écran quand le libellé seul est ambigu ; doit contenir le libellé visible (« Actions pour Clavier »).
animation"anchor-pop" | "card-deal" | "drum-roll" | "fade" | "outline-trace" | "tile-build" | "turn-over"'fade'Animation d'ouverture et de fermeture du menu.
disabledbooleanfalseDésactive le bouton.
label (obligatoire)string—Libellé du bouton qui ouvre le menu.

Events

Reactevent.detailDescription
onCrSelectstringÉmis quand une action est choisie ; detail : sa valeur.

CSS parts

To style it from outside: cr-menu::part(name) { … }

PartDescription
itemUne action.
menuLe panneau du menu.
triggerLe bouton qui ouvre le menu.

On this page