components/Menu
import { … } from 'zidane-ui'ui/src/components/Menu.tsx
Components#
MenuComponent#
Padding + role for a list of rows inside a floating surface; a menu / listbox handles the
arrow keys.
function Menu(props: MenuProps): ElementParameters
| Name | Type | Description |
|---|---|---|
| props | MenuProps | Component props. |
Returns
ElementProps
| Name | Type | Default | Description |
|---|---|---|---|
| aria-label? | string | Accessible name of the list. | |
| children | ReactNode | The rows, sections and notes. | |
| className? | string | Extra classes on the list element. | |
| role? | 'group' | 'listbox' | 'menu' | 'menu' | The list's ARIA role. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
MenuNoteComponent#
A note, hint or empty state inside a menu: sans, muted, row-aligned.
function MenuNote(props: MenuNoteProps): ElementParameters
| Name | Type | Description |
|---|---|---|
| props | MenuNoteProps | Component props. |
Returns
ElementProps
| Name | Type | Description |
|---|---|---|
| children | ReactNode | The note text. |
| className? | string | Extra classes on the note. |
| icon? | string | Icon class shown before the text, such as |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
MenuRowComponent#
Renders one row of a menu, list or picker: icon, title, optional description and a trailing
slot. checked marks the current choice with a check, toggle shows a switch, and active
marks the keyboard cursor. Use render to draw another element with the row's look. The
ref goes to the button.
const MenuRow: ForwardRefExoticComponent<MenuRowProps & RefAttributes<HTMLButtonElement>>Props
| Name | Type | Default | Description |
|---|---|---|---|
| active? | boolean | Keyboard cursor / hovered-by-nav row. | |
| checked? | boolean | The current choice: a check in the trailing slot. | |
| description? | ReactNode | Secondary text after the title. Inline it truncates to one line; | |
| descriptionClassName? | string | Applied to the description's own box (e.g. a fade that must hide its ellipsis too). | |
| destructive? | boolean | false | Tones the row as dangerous: the title and glyph take the danger colour. |
| hint? | string | Native tooltip (the row's | |
| icon? | ReactNode | Leading glyph, drawn muted. Use it only when it means something (a kind, a folder). No icon slot renders when omitted. | |
| render? | (props: MenuRowRenderProps) => ReactElement | Render another element with the row's look (a link). | |
| size? | 'sm' | 'md' | 'lg' | 'md' | Row density. |
| title | ReactNode | The row's label. | |
| toggle? | boolean | An on/off option: a switch in the trailing slot (use with | |
| trailing? | ReactNode | Content at the row's end, such as a keycap or a meta value. A check or switch from |
MenuSectionComponent#
A labelled group of rows.
function MenuSection(props: MenuSectionProps): ElementParameters
| Name | Type | Description |
|---|---|---|
| props | MenuSectionProps | Component props. |
Returns
ElementProps
| Name | Type | Description |
|---|---|---|
| children | ReactNode | The rows in the group. |
| className? | string | Extra classes on the group element. |
| label? | ReactNode | Heading above the rows. It names the group. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
| trailing? | ReactNode | Content at the end of the heading row, such as a count or an action. |
MenuSeparatorComponent#
Renders a thin rule between groups of rows. In a listbox it is drawing only, since a
listbox may hold only options and groups.
function MenuSeparator(props: MenuSeparatorProps): ElementParameters
| Name | Type | Description |
|---|---|---|
| props | MenuSeparatorProps | Component props. |
Returns
ElementProps
| Name | Type | Description |
|---|---|---|
| className? | string | Extra classes on the root element. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
MenuSwitchComponent#
The on/off glyph for an option row or a compact toggle button; the control around it owns the state.
function MenuSwitch(props: MenuSwitchProps): ElementParameters
| Name | Type | Description |
|---|---|---|
| props | MenuSwitchProps | Component props. |
Returns
ElementProps
| Name | Type | Description |
|---|---|---|
| className? | string | Extra classes on the root element. |
| on | boolean | Whether the switch is on. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
Functions#
focusMenuRowFunction#
Focus the row a menu opens on: the current choice, else the first enabled row. Returns false when there is no row to take focus.
function focusMenuRow(root: HTMLElement): booleanParameters
| Name | Type | Description |
|---|---|---|
| root | HTMLElement | The element holding the rows. |
Returns
booleanhandleMenuKeyDownFunction#
Arrow / Home / End / first-letter navigation between the enabled rows
under event.currentTarget. Handled keys stop here: the surface is portaled,
and React would otherwise bubble them into the composer behind it.
function handleMenuKeyDown(event: KeyboardEvent<HTMLElement>): voidParameters
| Name | Type | Description |
|---|---|---|
| event | KeyboardEvent<HTMLElement> | The keydown event of the list. Keys typed in a text field, or with Alt, Ctrl or Meta held, are ignored. |
useRowHintFunction#
Explanations for a compact list: the hovered (or focused) row's text, else
fallback (the current row's). Spread bind(text) on each row and render
the returned text in a MenuNote under the list.
function useRowHint(
fallback: string | undefined,
): { bind: (text: string | undefined) => { onBlur: () => void; onFocus: () => void; onMouseEnter: () => void; onMouseLeave: () => void }; hint: string | undefined }Parameters
| Name | Type | Description |
|---|---|---|
| fallback | string | undefined | The text shown while no row is hovered or focused, usually the current row's. |
Returns
{ bind: (text: string | undefined) => { onBlur: () => void; onFocus: () => void; onMouseEnter: () => void; onMouseLeave: () => void }; hint: string | undefined }hint, the text to show, and bind(text), which returns the hover and focus handlers
to spread on a row.
Interfaces#
MenuNotePropsInterface#
Props for MenuNote.
interface MenuNotePropsProperties
| Name | Type | Description |
|---|---|---|
| children | ReactNode | The note text. |
| className? | string | Extra classes on the note. |
| icon? | string | Icon class shown before the text, such as |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
MenuPropsInterface#
Props for Menu.
interface MenuPropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| aria-label? | string | Accessible name of the list. | |
| children | ReactNode | The rows, sections and notes. | |
| className? | string | Extra classes on the list element. | |
| role? | 'group' | 'listbox' | 'menu' | 'menu' | The list's ARIA role. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
MenuRowPropsInterface#
Props of MenuRow. It also accepts the attributes of a button, except title.
interface MenuRowProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'title'>Properties
| Name | Type | Default | Description |
|---|---|---|---|
| active? | boolean | Keyboard cursor / hovered-by-nav row. | |
| checked? | boolean | The current choice: a check in the trailing slot. | |
| description? | ReactNode | Secondary text after the title. Inline it truncates to one line; | |
| descriptionClassName? | string | Applied to the description's own box (e.g. a fade that must hide its ellipsis too). | |
| destructive? | boolean | false | Tones the row as dangerous: the title and glyph take the danger colour. |
| hint? | string | Native tooltip (the row's | |
| icon? | ReactNode | Leading glyph, drawn muted. Use it only when it means something (a kind, a folder). No icon slot renders when omitted. | |
| render? | (props: MenuRowRenderProps) => ReactElement | Render another element with the row's look (a link). | |
| size? | 'sm' | 'md' | 'lg' | 'md' | Row density. |
| title | ReactNode | The row's label. | |
| toggle? | boolean | An on/off option: a switch in the trailing slot (use with | |
| trailing? | ReactNode | Content at the row's end, such as a keycap or a meta value. A check or switch from |
MenuRowRenderPropsInterface#
Props MenuRowProps.render receives to spread onto the element it renders.
interface MenuRowRenderPropsProperties
| Name | Type | Description |
|---|---|---|
| children | ReactNode | The row's content: icon, title, description and trailing slot. |
| className | string | The row's classes, merged with the caller's |
| data-active? | '' | Set to an empty string while the row is |
| data-checked? | '' | The current choice: where focus lands when the menu opens. |
| data-destructive? | '' | Set to an empty string while the row is |
| data-size | 'sm' | 'md' | 'lg' | The row's |
| title? | string | Native tooltip, from the |
MenuSectionPropsInterface#
Props for MenuSection.
interface MenuSectionPropsProperties
| Name | Type | Description |
|---|---|---|
| children | ReactNode | The rows in the group. |
| className? | string | Extra classes on the group element. |
| label? | ReactNode | Heading above the rows. It names the group. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
| trailing? | ReactNode | Content at the end of the heading row, such as a count or an action. |
MenuSeparatorPropsInterface#
Props for MenuSeparator.
interface MenuSeparatorPropsProperties
| Name | Type | Description |
|---|---|---|
| className? | string | Extra classes on the root element. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |
MenuSwitchPropsInterface#
Props for MenuSwitch.
interface MenuSwitchPropsProperties
| Name | Type | Description |
|---|---|---|
| className? | string | Extra classes on the root element. |
| on | boolean | Whether the switch is on. |
| style? | CSSProperties | Inline styles on the root element, merged after the component's own. |