Actions
SplitButton
A main action with a menu of related ones, such as Save next to Save as draft. Two real buttons in a group, so each has its own name and Tab stop.
import { SplitButton } from '@reactloom/ui';Examples
Save and related actions
Menu items can have descriptions and sections, like any Menu.
import { SplitButton } from '@reactloom/ui';
import { useState } from 'react';
export default function Example() {
const [last, setLast] = useState<string>();
return (
<div style={{ display: 'grid', gap: 8, justifyItems: 'center' }}>
<SplitButton
aria-label="Save options"
onClick={() => setLast('save')}
onAction={setLast}
items={[
{ key: 'draft', label: 'Save as draft' },
{ key: 'copy', label: 'Save a copy', description: 'Keeps the original' },
{ type: 'section', label: 'Export', items: [{ key: 'pdf', label: 'PDF' }, { key: 'docx', label: 'Word document' }] },
]}
>
Save
</SplitButton>
<span role="status">{last ? `Chose “${last}”` : ''}</span>
</div>
);
}Variants, sizes and states
loading affects only the main action; disabled affects both halves.
import { HStack, SplitButton } from '@reactloom/ui';
const items = [
{ key: 'schedule', label: 'Schedule…' },
{ key: 'test', label: 'Send a test' },
];
export default function Example() {
return (
<HStack wrap>
<SplitButton items={items} aria-label="Send options">Send</SplitButton>
<SplitButton items={items} aria-label="Send options" variant="secondary" size="sm">
Send
</SplitButton>
<SplitButton items={items} aria-label="Send options" variant="outline" loading>
Sending
</SplitButton>
<SplitButton items={items} aria-label="Send options" disabled>
Send
</SplitButton>
</HStack>
);
}API reference
| Prop | Type | Default |
|---|---|---|
childrenrequiredLabel of the main action. | ReactNode | — |
onClickThe main action. | MouseEventHandler | — |
itemsrequiredRelated actions, as for Menu (sections, icons, shortcuts, submenus). | MenuEntry[] | — |
onActionCalled with the chosen menu item. | (key: string) => void | — |
menuLabelAccessible name of the menu button. | string | 'More options' |
variant · sizeAs on Button. | | 'primary' · 'md' |
loading · disabledloading shows a spinner on the main button; disabled disables both. | boolean | — |
startIcon · menuIconIcon before the label; replacement for the chevron. | ReactNode | — |
placementMenu placement. | OverlayPlacement | 'bottom-end' |
menuPropsSelection, renderItem and menu slots. | MenuCommonProps | — |
classNames · stylesroot, button and trigger. | Partial<Record<SplitButtonSlot, …>> | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): root, button, trigger.
CSS variables
| Variable | Default |
|---|---|
--pl-split-button-divider | rgb(255 255 255 / 0.35) |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-variant] | present when on |
Accessibility
- Rendered as role="group"; name it with aria-label when the label alone is not enough (for example “Save options”).
- The menu button has its own accessible name and opens a WAI-ARIA menu with arrow-key navigation and type-ahead.
| Key | Action |
|---|---|
| Tab | Move between the main button and the menu button |
| Enter / Space | Run the main action, or open the menu |
| ↓ / ↑ on the menu button | Open the menu at the first or last item |
| Escape | Close the menu |
Usage guidelines
Do
- Use when one action is the obvious default and others are variations of it.
Don’t
- Don’t hide unrelated actions in the menu; use a Menu or a Toolbar instead.
- Don’t use when the actions are equally likely; show them as separate buttons.