Actions
Menu
A list of actions opened from a button.
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.
| Value | Effect |
|---|---|
fade | subtle fade (default) |
anchor-pop | the menu springs out of the button with a slight bounce, and shrinks back into it on selection |
turn-over | the panel flips over like a card |
card-deal | the actions are dealt like cards; the chosen one flies back to the button |
drum-roll | the actions roll in on a drum, then roll away downwards |
outline-trace | a purple → cyan outline draws the panel, then the items sweep in |
tile-build | the 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
| Key | Button | Open menu |
|---|---|---|
| Enter, Space, Down Arrow | opens the menu on the first action | selects the action |
| Up Arrow | opens the menu on the last action | previous 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,menuandmenuitemroles. - 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
| Property | Type | Default | Description |
|---|---|---|---|
accessibleLabel | string | — | 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. |
disabled | boolean | false | Désactive le bouton. |
label (obligatoire) | string | — | Libellé du bouton qui ouvre le menu. |
Events
| React | event.detail | Description |
|---|---|---|
onCrSelect | string | Émis quand une action est choisie ; detail : sa valeur. |
CSS parts
To style it from outside: cr-menu::part(name) { … }
| Part | Description |
|---|---|
item | Une action. |
menu | Le panneau du menu. |
trigger | Le bouton qui ouvre le menu. |