Examples

Save and related actions

Menu items can have descriptions and sections, like any Menu.

Preview
Example.tsx
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.

Preview
Example.tsx
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

SplitButton props
PropTypeDefault
childrenrequired
Label of the main action.
ReactNode—
onClick
The main action.
MouseEventHandler—
itemsrequired
Related actions, as for Menu (sections, icons, shortcuts, submenus).
MenuEntry[]—
onAction
Called with the chosen menu item.
(key: string) => void—
menuLabel
Accessible name of the menu button.
string'More options'
variant · size
As on Button.
'primary' · 'md'
loading · disabled
loading shows a spinner on the main button; disabled disables both.
boolean—
startIcon · menuIcon
Icon before the label; replacement for the chevron.
ReactNode—
placement
Menu placement.
OverlayPlacement'bottom-end'
menuProps
Selection, renderItem and menu slots.
MenuCommonProps—
classNames · styles
root, 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

VariableDefault
--pl-split-button-dividerrgb(255 255 255 / 0.35)

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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.
Keyboard interactions
KeyAction
TabMove between the main button and the menu button
Enter / SpaceRun the main action, or open the menu
↓ / ↑ on the menu buttonOpen the menu at the first or last item
EscapeClose 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.