Overlays
ContextMenu
Actions for an area, opened where the user right-clicks, long-presses on touch, or presses Shift+F10 or the Menu key.
import { ContextMenu } from '@reactloom/ui';Examples
File list
Each row has its own menu.
import { ContextMenu, Stack, Text } from '@reactloom/ui';
import { useState } from 'react';
const files = ['Q3 report.pdf', 'Budget 2031.xlsx', 'Logo.svg'];
export default function Example() {
const [log, setLog] = useState('');
return (
<Stack gap="2" style={{ maxInlineSize: 360 }}>
<ul aria-label="Files" style={{ display: 'grid', gap: 6, margin: 0, padding: 0, listStyle: 'none' }}>
{files.map((file) => (
<li key={file}>
<ContextMenu
aria-label={`Actions for ${file}`}
items={[
{ key: 'open', label: 'Open' },
{ key: 'rename', label: 'Rename', shortcut: 'F2' },
{ type: 'section', items: [{ key: 'delete', label: 'Delete', tone: 'danger' }] },
]}
onAction={(key) => setLog(`${key} ${file}`)}
>
<button type="button" style={{ inlineSize: '100%', padding: 10, textAlign: 'start', border: '1px solid var(--pl-color-border-default)', borderRadius: 6, background: 'var(--pl-color-bg-surface)', color: 'inherit', font: 'inherit' }}>
{file}
</button>
</ContextMenu>
</li>
))}
</ul>
<Text size="sm" role="status">
{log && `Chose: ${log}`}
</Text>
</Stack>
);
}Canvas
Disabled items and sections.
Right-click, long-press or press Shift+F10 here. Shapes: none
import { ContextMenu } from '@reactloom/ui';
import { useState } from 'react';
export default function Example() {
const [shapes, setShapes] = useState<string[]>([]);
return (
<ContextMenu
aria-label="Canvas"
items={[
{ key: 'rect', label: 'Add rectangle' },
{ key: 'circle', label: 'Add circle' },
{ type: 'section', items: [{ key: 'clear', label: 'Clear canvas', disabled: shapes.length === 0 }] },
]}
onAction={(key) => setShapes((list) => (key === 'clear' ? [] : [...list, key]))}
>
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- focusable so Shift+F10 opens the menu */}
<div tabIndex={0} role="region" aria-label={`Canvas, ${shapes.length} shapes`} style={{ minBlockSize: 140, padding: 12, border: '1px dashed var(--pl-color-border-strong)', borderRadius: 8 }}>
Right-click, long-press or press Shift+F10 here. Shapes: {shapes.join(', ') || 'none'}
</div>
</ContextMenu>
);
}API reference
| Prop | Type | Default |
|---|---|---|
childrenrequiredThe area; make it focusable. | ReactElement | — |
itemsrequiredSame as Menu. | MenuEntry[] | — |
onActionrequired | (key) => void | — |
aria-labelrequiredName of the menu. | string | — |
onOpenChange | (open) => void | — |
longPressDelayTouch long-press in ms. | number | 500 |
disabled | boolean | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Accessibility
- The same menu keyboard model as Menu; focus returns to the area when it closes.
- Shift+F10 and the Menu key open it at the focused area.
| Key | Action |
|---|---|
| Shift+F10 / Menu key | Open |
| ↑ / ↓ | Move |
| Enter | Run |
| Escape | Close |
Usage guidelines
Do
- Offer the same actions in a visible menu button too.
Don’t
- Don’t put actions only in a context menu — people don’t know it is there.