Components / Overlays
Menu
Dropdown list of actions. Arrow keys, Home/End, typing a letter and Esc all work.
import { Menu } from "@stylhero/ui";
Example
Code
import { Button, Menu } from "@stylhero/ui";
function MenuExample() {
return (
<Menu trigger={<Button variant="secondary">Actions</Button>} items={[
{ label: "Rename", onSelect: () => {} },
{ label: "Duplicate", shortcut: "Ctrl+D", onSelect: () => {} },
{ label: "Open on GitHub", href: "https://github.com/raiburn/stylhero" },
"separator",
{ label: "Delete", danger: true, onSelect: () => {} },
]} />
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items required |
MenuItem[] |
- | |
trigger required |
ReactElement |
- | The element that opens the menu, e.g. <IconButton label="More"><MoreHorizontal /></IconButton>. |
className |
string |
- | |
placement |
Placement |
"bottom-start" |
Types
type MenuItem = MenuAction | "separator";
type MenuAction = {
label: string;
icon?: ReactNode;
onSelect?: () => void;
/** Renders a link instead of a button. */
href?: string;
/** Red, for destructive actions. Put them last. */
danger?: boolean;
disabled?: boolean;
/** Keyboard hint on the right, e.g. "Ctrl+D". */
shortcut?: string;
};
Keyboard
| Key | Does |
|---|---|
| Enter / Space / ArrowDown | Open the menu from the trigger |
| ArrowDown / ArrowUp | Move through the items |
| Typing a letter | Jumps to the next item that starts with it |
| Enter | Activates the item |
| Esc | Closes it and returns focus to the trigger |
Accessibility
- Follows the ARIA menu pattern (
role="menu"andmenuitem), with focus kept on the active item.
Generated from src/components/Menu.tsx. Something wrong or missing? Open an issue.