Split button
Split button
Dual-action trigger: primary action on the left, trailing chevron on the right opening an aligned dropdown menu.
Dependencies
Interaction states
- idle — A two-part capsule with a thin line divider; pressing either half gives the whole capsule 2%.
- open — The menu grows out of the chevron, which turns over; a highlight glides between rows.
- loading — The icon blurs into a spinner and the label morphs ("Publish" → "Publishing"); clicks are swallowed.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/split-buttonFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
Publish & deploy
Primary "Publish" action with dropdown options for "Schedule" or "Publish as draft".
Save & export
"Save" main action paired with "Export as PDF" or "Export as JSON".
Git & release
"Commit changes" with "Commit and push" or "Create PR" secondary options.
What it handles
- Dual-action trigger — Independent click handlers for the primary action and the secondary chevron trigger.
- Aligned floating menu — Floating menu opens directly below the button’s right edge with thin line borders and zero fuzzy shadows.
- 180° chevron rotation — Chevron smoothly rotates with organic spring easing when opened.
- Keyboard accessible — Navigate open menu items with ArrowUp, ArrowDown, Home, End, and dismiss with Escape.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
import { SplitButton } from "@/components/split-button";
<SplitButton
label="Save changes"
onClick={() => save()}
menuItems={[
{ id: "save-draft", label: "Save as draft", onSelect: () => saveDraft() },
{ id: "export", label: "Export backup", onSelect: () => exportBackup() },
]}
/>Props
| Prop | Type | Description |
|---|---|---|
| label | string | – · Text of the primary action. |
| onClick | () => void | – · Called when the primary action button is clicked. |
| menuItems | SplitMenuItem[] | – · List of secondary actions shown in the dropdown menu. |
| variant | "primary" | "secondary" | "destructive" | "primary" · Color scheme and visual tone. |
| size | "sm" | "md" | "lg" | "md" · Height and typography scale. |
| loading | boolean | false · Shows a spinner inside the primary button. |
| disabled | boolean | false · Disables both primary and dropdown actions. |
Accessibility & motion
- No external dropdown library dependency: lightweight self-contained menu logic with full keyboard handling. - Clicking outside or pressing Escape cleanly closes the menu.
pnpm dlx shadcn@4.21.5 add @cavemio/split-button