PixelDosa UI

Split Button

A primary action paired with a menu of related alternatives, with accessible keyboard navigation and loading and disabled states.

No action selected yet.

Installation

bash
npx shadcn@latest add @pixeldosa/split-button

Requires `cn` at `@/lib/utils`, which `npx shadcn init` creates. Radix Dropdown Menu is installed as a direct dependency and provides menu focus management, keyboard navigation, dismissal, and portal behavior.

Usage

import { SplitButton } from "@/components/ui/split-button";

export function PublishActions() {
  return (
    <SplitButton
      label="Publish"
      onClick={publishNow}
      items={[
        { label: "Schedule publish", onClick: schedulePublish },
        { label: "Save as draft", onClick: saveDraft, separator: true },
      ]}
    />
  );
}

Keep the most common action on the primary segment. Use the menu for related alternatives that should not compete for the same visual priority. If all actions are peers, use an Action Menu or Button Group instead.

Menu items can include an icon, be disabled, or introduce a separator before themselves. The menu closes after selection and returns focus to its trigger.

Props

PropTypeDefaultDescription
labelstring—Visible label for the primary action.
onClick(event: React.MouseEvent<HTMLButtonElement>) => void—Handler for the primary action.
itemsSplitButtonItem[]—Related menu actions; each item has a label, onClick, and optional icon, disabled, and separator.
variant"primary" | "secondary" | "outline" | "ghost""primary"Visual treatment shared by both segments.
size"sm" | "md" | "lg""md"Height and type size for both segments.
disabledbooleanfalseDisables both segments.
loadingbooleanfalseDisables both segments, marks the primary action busy, and shows a reduced-motion-aware indicator.
menuPlacement"bottom" | "top""bottom"Preferred side for the menu; Radix adjusts placement to avoid viewport collisions.
classNamestring—Additional classes applied to the button group.
type"button" | "submit" | "reset""button"Native button type for the primary action.

Other native button attributes are forwarded to the primary action.

why it's built this way

Engineering Notes

Uses Radix Dropdown Menu rather than hand-rolled menu roles, pointer dismissal, and focus management: this preserves arrow-key navigation, typeahead, Escape handling, focus restoration, and collision-aware placement for the secondary actions. The primary action remains an independent native button, so its click behavior and form semantics do not depend on opening the menu. CVA owns the variant and size matrix and exports splitButtonVariants for consumer extension; semantic classes keep colors theme-driven, while the separate icon trigger has its own accessible name.

how it moves, and when it doesn't

Motion Notes

Menu content appears without an entrance animation so focus movement and action availability remain the motion; adding a decorative menu transition would add little orientation value for this compact control. Button color feedback uses the generated instant duration and standard easing tokens. The loading indicator rotates only to communicate ongoing work and becomes static under prefers-reduced-motion; the button remains mounted, disabled, and marked busy so progress is still conveyed without animation.