Cómo funciona
Two native buttons sit inside one rounded shape, separated by a hairline seam. Each half has its own hover and press layer, so it is always clear which part will act. The chevron opens a role="menu" that grows from its corner with a short ease-out, and the chevron itself turns with a spring. Items can carry an icon, a one-line description, a shortcut hint or a danger tone.
Úsalo para
- One action is clearly the most common and a few variations of it are needed, such as Publish with Schedule and Save as draft.
- Toolbars and footers where space allows only one button.
Busca otra opción cuando
- The actions are equally important: show them as separate buttons.
- More than about seven actions: use a full menu or a page.
Uso
import { SplitButton } from './SplitButton.jsx'
export function PublishActions({ onPublish, onSchedule, onSaveDraft, onDiscard }) {
return (
<SplitButton
label="Publish"
menuLabel="More publish options"
onClick={onPublish}
items={[
{ id: 'schedule', label: 'Schedule…', description: 'Pick a date and time', onSelect: onSchedule },
{ id: 'draft', label: 'Save as draft', shortcut: '⌘D', onSelect: onSaveDraft },
{ divider: true },
{ id: 'discard', label: 'Discard changes', danger: true, onSelect: onDiscard },
]}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
label | ReactNode | — | Text of the primary action. |
onClick | (event) => void | — | Runs the primary action. |
items | Array<{ id, label, description?, icon?, shortcut?, danger?, disabled?, divider?, onSelect? }> | [] | Menu entries. An entry with divider: true draws a separator. shortcut is shown only, it does not bind keys. |
onSelect | (item) => void | — | Called with the chosen item, after the menu closes. |
variant | 'primary' | 'ink' | 'secondary' | 'primary' | Colour. |
size | 'sm' | 'md' | 'lg' | 'md' | Height 32, 40 or 44px. |
align | 'start' | 'end' | 'end' | Which edge the menu lines up with. |
side | 'bottom' | 'top' | 'bottom' | Opens the menu below or above, for buttons in footers. |
menuLabel | string | 'More options' | Accessible name of the chevron and the menu. |
loading | boolean | false | Shows a spinner on the primary half and disables it; the menu still works. |
disabled | boolean | false | Disables both halves. |
Accesibilidad
- The primary half and the chevron are separate native buttons; the chevron has aria-haspopup="menu", aria-expanded and an accessible name from menuLabel.
- ArrowDown or ArrowUp on the chevron opens the menu on the first or last item; in the menu, arrows wrap, Home and End jump, typing a letter jumps to a matching item.
- Enter or Space chooses; Escape closes and returns focus to the chevron; Tab or clicking outside closes.
- Items use role="menuitem" with roving tabindex; disabled items are skipped and carry aria-disabled.
- Reduced motion replaces the menu's scale with a fade and stops the chevron turning.
Movimiento
The menu fades in and grows from 96% over 240ms ease-out, from the chevron's corner. The chevron turns 180° in 240ms with a slight spring overshoot.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
SplitButton.jsxsplit-button.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.



