Actions · Material 3: Split buttons
Split button
A main action plus a menu of related ones, joined in one shape. The chevron flips when the menu opens.
Examples and variants
Basic
Publish now, or pick another option.
function SplitButtonBasic() {
return (
<SplitButton
menu={
<>
<DropdownMenuItem>Save as draft</DropdownMenuItem>
<DropdownMenuItem>Schedule</DropdownMenuItem>
</>
}
>
Publish
</SplitButton>
)
}Spec drawing
Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.
Install
With the CLI
The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/split-button.jsonBy hand
No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.
Install the packages it uses.
Terminalnpm install @base-ui/react class-variance-authority cn lucide-reactCopy these 3 files to the same paths in your project. Imports use the
@/alias for your project root.components/ui/button.tsxbutton
components/ui/button.tsx"use client" import { useRef, useState } from "react" import { Button as ButtonPrimitive } from "@base-ui/react/button" import { CheckIcon, XIcon } from "lucide-react" import { tokenMs } from "@/lib/motion/token-ms" import { cva, type VariantProps } from "class-variance-authority" import { cn } from "cn" // Minimal: no strokes on controls (DESIGN.md rule 11), token sizes, token focus ring, // liquid press squash instead of shadcn's translate-y nudge. // Every visual spec reads a component token (styles/tokens/components.css, --button-*). // Sizes: sm | md | lg (default = md). Variants: primary (default) | secondary | outline | ghost | link. const filled = { primary: "bg-(--button-primary-container) text-(--button-primary-label) hover:bg-(--button-primary-container-hover) active:bg-(--button-primary-container-pressed)", secondary: "bg-(--button-secondary-container) text-(--button-secondary-label) hover:bg-(--button-secondary-container-hover) active:bg-(--button-secondary-container-pressed) aria-expanded:bg-(--button-secondary-container-hover)", } const buttonVariants = cva( "liquid-press group/button relative inline-flex shrink-0 items-center justify-center overflow-hidden rounded-(--button-corner) border-solid border-(length:--button-stroke-width) border-(--stroke-color-default) bg-clip-padding text-(length:--button-label-size) [font-weight:var(--button-label-weight)] whitespace-nowrap outline-none select-none focus-visible:shadow-(--focus-ring) disabled:pointer-events-none disabled:bg-(--button-container-disabled) disabled:text-(--button-label-disabled) disabled:shadow-none aria-invalid:shadow-(--focus-ring-invalid) [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-(--button-icon-size)", { variants: { variant: { primary: filled.primary, default: filled.primary, secondary: filled.secondary, outline: "bg-(--button-outline-container) text-(--button-secondary-label) shadow-(--button-outline-elevation) hover:bg-(--button-outline-container-hover) active:bg-(--button-outline-container-pressed) aria-expanded:bg-(--button-outline-container-hover)", ghost: "text-(--button-secondary-label) hover:bg-(--button-ghost-container-hover) active:bg-(--button-ghost-container-pressed) aria-expanded:bg-(--button-ghost-container-hover) disabled:bg-transparent", destructive: "", link: "text-(--button-link-label) underline-offset-4 hover:underline disabled:bg-transparent", }, size: { xs: "active:not-disabled:rounded-(--button-corner-pressed) h-(--button-height-xs) gap-(--button-gap-sm) px-(--button-padding-x-xs) text-(length:--button-label-size-sm) [&_svg:not([class*='size-'])]:size-(--button-icon-size-sm)", sm: "active:not-disabled:rounded-(--button-corner-pressed) h-(--button-height-sm) gap-(--button-gap-sm) px-(--button-padding-x-sm) [&_svg:not([class*='size-'])]:size-(--button-icon-size-sm)", md: "active:not-disabled:rounded-(--button-corner-pressed) h-(--button-height-md) gap-(--button-gap) px-(--button-padding-x-md) has-data-[icon=inline-end]:pe-(--button-padding-x-sm) has-data-[icon=inline-start]:ps-(--button-padding-x-sm)", default: "active:not-disabled:rounded-(--button-corner-pressed) h-(--button-height-md) gap-(--button-gap) px-(--button-padding-x-md) has-data-[icon=inline-end]:pe-(--button-padding-x-sm) has-data-[icon=inline-start]:ps-(--button-padding-x-sm)", lg: "active:not-disabled:rounded-(--button-corner-pressed) h-(--button-height-lg) gap-(--button-gap) px-(--button-padding-x-lg) has-data-[icon=inline-end]:pe-(--button-padding-x-md) has-data-[icon=inline-start]:ps-(--button-padding-x-md) [&_svg:not([class*='size-'])]:size-(--button-icon-size-lg)", icon: "size-(--icon-button-size-md) rounded-(--icon-button-corner)", "icon-xs": "size-(--button-height-xs) rounded-(--icon-button-corner) [&_svg:not([class*='size-'])]:size-(--button-icon-size-sm)", "icon-sm": "size-(--icon-button-size-sm) rounded-(--icon-button-corner) [&_svg:not([class*='size-'])]:size-(--button-icon-size-sm)", "icon-md": "size-(--icon-button-size-md) rounded-(--icon-button-corner)", "icon-lg": "size-(--icon-button-size-lg) rounded-(--icon-button-corner) [&_svg:not([class*='size-'])]:size-(--button-icon-size-lg)", }, tone: { neutral: "", danger: "", success: "", }, }, // tone: colour intent on any variant (component-model.md §7). destructive = tone danger. compoundVariants: [ { tone: "danger", variant: ["primary", "default", "secondary", "outline", "destructive"], className: "bg-(--button-danger-container) text-(--button-danger-label) shadow-none hover:bg-(--button-danger-container-hover) active:bg-(--button-danger-container-pressed) [--focus-ring-color:var(--color-danger)]", }, { tone: "danger", variant: ["ghost", "link"], className: "text-(--button-danger-label) hover:bg-(--button-danger-container) active:bg-(--button-danger-container-hover) [--focus-ring-color:var(--color-danger)]", }, { tone: "success", variant: ["primary", "default", "secondary", "outline"], className: "bg-(--button-success-container) text-(--button-success-label) shadow-none hover:bg-(--button-success-container-hover) active:bg-(--button-success-container-pressed)", }, ], defaultVariants: { variant: "primary", size: "md", tone: "neutral", }, } ) type Wash = { id: number; x: number; y: number } type Status = "idle" | "loading" | "success" | "error" type ButtonProps = ButtonPrimitive.Props & VariantProps<typeof buttonVariants> & { /** * The button shows its own result inside a fixed width: spinner, then a * check or a cross. Prefer this to a toast (component-model.md §5). */ status?: Status /** "hold": the click only happens after holding for --duration-fill (pointer, Space or Enter). */ confirm?: "hold" /** Screen reader text for the success and error states. */ statusLabel?: { success?: string; error?: string } /** @deprecated use status="loading" */ loading?: boolean /** @deprecated use status="success" */ success?: boolean } function Button({ className, variant = "primary", size = "md", tone = "neutral", status: statusProp, confirm, statusLabel, loading = false, success = false, children, onClick, onPointerUp, onPointerDown, onPointerLeave, onKeyDown, onKeyUp, ...props }: ButtonProps) { const status: Status = statusProp ?? (loading ? "loading" : success ? "success" : "idle") const busy = status === "loading" const [wash, setWash] = useState<Wash | null>(null) const [held, setHeld] = useState(false) const holdTimer = useRef(0) const allowClick = useRef(false) const self = useRef<HTMLElement | null>(null) const resolvedTone = variant === "destructive" ? "danger" : tone function startHold(element: HTMLElement) { if (confirm !== "hold" || busy) return self.current = element setHeld(true) window.clearTimeout(holdTimer.current) holdTimer.current = window.setTimeout(() => { setHeld(false) allowClick.current = true self.current?.click() allowClick.current = false }, tokenMs("--duration-fill", element)) } function stopHold() { if (confirm !== "hold") return setHeld(false) window.clearTimeout(holdTimer.current) } function handleClick(event: Parameters<NonNullable<ButtonProps["onClick"]>>[0]) { if (busy || (confirm === "hold" && !allowClick.current)) { event.preventDefault() return } onClick?.(event) } function handlePointerUp(event: Parameters<NonNullable<ButtonProps["onPointerUp"]>>[0]) { onPointerUp?.(event) stopHold() if (event.defaultPrevented || busy || confirm === "hold") return if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return const motion = event.currentTarget.closest<HTMLElement>("[data-motion]")?.dataset.motion if (motion === "calm" || motion === "still") return const rect = event.currentTarget.getBoundingClientRect() setWash({ id: Date.now(), x: event.clientX - rect.left, y: event.clientY - rect.top, }) } const showResult = status === "success" || status === "error" return ( <ButtonPrimitive data-slot="button" data-icon={typeof size === "string" && size.startsWith("icon") ? "" : undefined} data-tone={resolvedTone} data-status={status} data-confirm={confirm} aria-busy={busy || undefined} aria-disabled={busy || undefined} {...props} className={cn( buttonVariants({ variant, size, tone: resolvedTone, className }), status === "error" && "animate-[isotope-nudge_var(--duration-fast)_var(--ease-out)]" )} onClick={handleClick} onPointerUp={handlePointerUp} onPointerDown={(event) => { onPointerDown?.(event) if (event.button === 0) startHold(event.currentTarget) }} onPointerLeave={(event) => { onPointerLeave?.(event) stopHold() }} onKeyDown={(event) => { onKeyDown?.(event) if (confirm === "hold" && (event.key === " " || event.key === "Enter") && !event.repeat) { startHold(event.currentTarget) } }} onKeyUp={(event) => { onKeyUp?.(event) if (event.key === " " || event.key === "Enter") stopHold() }} > {confirm === "hold" ? ( <span aria-hidden data-held={held ? "" : undefined} className="hold-fill pointer-events-none absolute inset-y-0 left-0 w-full bg-current opacity-20" /> ) : null} <span className={cn( "button-label relative inline-flex items-center justify-center gap-[inherit]", (busy || showResult) && "opacity-0 blur-(--motion-blur-enter) transition-[opacity,filter] duration-(--duration-fast) ease-(--ease-out)" )} > {children} {confirm === "hold" ? <span className="sr-only">(hold to confirm)</span> : null} </span> {showResult ? ( <span className="button-success absolute inset-0 inline-flex items-center justify-center" role="status"> <span className="sr-only"> {status === "success" ? statusLabel?.success ?? "Done" : statusLabel?.error ?? "Failed"} </span> {status === "success" ? <CheckIcon aria-hidden /> : <XIcon aria-hidden />} </span> ) : null} {busy ? ( <span className="absolute inset-0 inline-flex items-center justify-center gap-inline-xs"> <span className="sr-only">Loading</span> {[0, 1, 2].map((dot) => ( <span key={dot} aria-hidden className="size-inline-xs rounded-full bg-current animate-[isotope-pulse_var(--duration-pulse)_var(--ease-out)_infinite]" style={{ animationDelay: `calc(var(--duration-stagger) * ${dot})` }} /> ))} </span> ) : null} {wash ? ( <span key={wash.id} aria-hidden onAnimationEnd={() => setWash(null)} className="pointer-events-none absolute size-[calc(var(--size-control-lg)*4)] rounded-full bg-current animate-[isotope-wash_var(--duration-settle)_var(--ease-out)_both]" style={{ left: wash.x, top: wash.y }} /> ) : null} </ButtonPrimitive> ) } export { Button, buttonVariants } export type { ButtonProps }components/ui/dropdown-menu.tsxdropdown-menu
components/ui/dropdown-menu.tsx"use client" import * as React from "react" import { Menu as MenuPrimitive } from "@base-ui/react/menu" import { ChevronRightIcon } from "lucide-react" import { cn } from "cn" import { layoutTop } from "@/lib/motion/layout-offset" import { usePortalMotion } from "@/lib/overlay" function DropdownMenu(props: MenuPrimitive.Root.Props) { return <MenuPrimitive.Root {...props} /> } function DropdownMenuTrigger(props: MenuPrimitive.Trigger.Props) { return <MenuPrimitive.Trigger data-slot="menu-trigger" {...props} /> } /* On phones (< 640px) a root menu presents as a bottom sheet with a scrim (component-model.md §3: one Menu, adaptive presentation). Submenus and presentation="popover" keep the anchored popover everywhere. */ function DropdownMenuContent({ className, children, side, align, sideOffset = 6, presentation = "auto", ...props }: MenuPrimitive.Popup.Props & Pick<MenuPrimitive.Positioner.Props, "side" | "align" | "sideOffset"> & { presentation?: "auto" | "popover" }) { const submenu = (props as Record<string, unknown>)["data-submenu"] !== undefined const sheet = presentation === "auto" && !submenu const ref = React.useRef<HTMLDivElement>(null) usePortalMotion(ref) return ( <MenuPrimitive.Portal> {sheet ? <MenuPrimitive.Backdrop className="menu-sheet-scrim fixed inset-0 z-dropdown" /> : null} <MenuPrimitive.Positioner className={cn("z-dropdown", sheet && "menu-sheet-positioner")} side={side} align={align} sideOffset={sideOffset} > <MenuPrimitive.Popup ref={ref} data-slot="menu-content" data-sheet={sheet || undefined} className={cn( "overlay-surface overlay-grow z-dropdown min-w-(--menu-min-width) rounded-(--menu-corner) p-(--menu-padding) text-sm text-foreground", className )} {...props} > <MenuHighlight>{children}</MenuHighlight> </MenuPrimitive.Popup> </MenuPrimitive.Positioner> </MenuPrimitive.Portal> ) } export function MenuHighlight({ children }: { children: React.ReactNode }) { const ref = React.useRef<HTMLDivElement>(null) const [box, setBox] = React.useState({ top: 0, height: 0, stretch: false, danger: false }) const [ready, setReady] = React.useState(false) React.useLayoutEffect(() => { const root = ref.current if (!root) return const read = () => { const item = root.querySelector<HTMLElement>("[data-highlighted]") if (!item) return const motion = root.closest<HTMLElement>("[data-motion]")?.dataset.motion setBox({ top: layoutTop(item, root), height: item.offsetHeight, stretch: item.hasAttribute("data-popup-open") && motion !== "calm" && motion !== "still", danger: item.dataset.tone === "danger", }) setReady(true) } read() const observer = new MutationObserver(read) observer.observe(root, { subtree: true, attributes: true, attributeFilter: ["data-highlighted", "data-popup-open", "data-motion"], }) const resize = new ResizeObserver(read) resize.observe(root) return () => { observer.disconnect() resize.disconnect() } }, []) return ( <div ref={ref} className="relative"> {ready ? ( <span aria-hidden className={cn( "menu-pill pointer-events-none absolute left-1 rounded-(--menu-item-corner) bg-(--menu-item-highlight) transition-[background-color] duration-(--duration-fast)", box.danger && "bg-(--color-danger-subtle)" )} style={{ top: box.top, height: box.height, right: box.stretch ? "calc(var(--motion-distance-lg) * -1)" : "var(--space-1)", }} /> ) : null} {children} </div> ) } function DropdownMenuItem({ className, tone = "neutral", ...props }: MenuPrimitive.Item.Props & { tone?: "neutral" | "danger" }) { return ( <MenuPrimitive.Item data-slot="menu-item" data-tone={tone} className={cn( "menu-item relative z-[1] flex cursor-default items-center gap-inline-sm rounded-(--menu-item-corner) text-sm outline-none data-disabled:text-(--menu-item-label-disabled)", tone === "danger" && "text-(--color-danger-fg)", className )} {...props} /> ) } function DropdownMenuCheckboxItem({ className, ...props }: MenuPrimitive.CheckboxItem.Props) { return ( <MenuPrimitive.CheckboxItem data-slot="menu-item" className={cn( "menu-item relative z-[1] flex cursor-default items-center rounded-(--menu-item-corner) text-sm outline-none", className )} {...props} /> ) } function DropdownMenuRadioGroup(props: MenuPrimitive.RadioGroup.Props) { return <MenuPrimitive.RadioGroup {...props} /> } function DropdownMenuRadioItem({ className, ...props }: MenuPrimitive.RadioItem.Props) { return ( <MenuPrimitive.RadioItem data-slot="menu-item" className={cn( "menu-item relative z-[1] flex cursor-default items-center rounded-(--menu-item-corner) text-sm outline-none", className )} {...props} /> ) } function DropdownMenuLabel({ className, ...props }: MenuPrimitive.GroupLabel.Props) { return ( <MenuPrimitive.GroupLabel className={cn("px-2 py-1 text-xs text-muted-foreground", className)} {...props} /> ) } function DropdownMenuSeparator({ className, ...props }: React.ComponentProps<"div">) { return <div aria-hidden className={cn("h-stack-sm", className)} {...props} /> } function DropdownMenuSub(props: MenuPrimitive.SubmenuRoot.Props) { return <MenuPrimitive.SubmenuRoot {...props} /> } function DropdownMenuSubTrigger({ className, children, ...props }: MenuPrimitive.SubmenuTrigger.Props) { return ( <MenuPrimitive.SubmenuTrigger data-slot="menu-sub-trigger" className={cn( "menu-item relative z-[1] flex w-full cursor-default items-center gap-inline-sm rounded-(--menu-item-corner) text-sm outline-none", className )} {...props} > {children} <ChevronRightIcon className="ml-auto size-icon-sm text-muted-foreground" /> </MenuPrimitive.SubmenuTrigger> ) } function DropdownMenuSubContent(props: MenuPrimitive.Popup.Props) { return <DropdownMenuContent data-submenu="" {...props} /> } function DropdownMenuShortcut({ className, ...props }: React.ComponentProps<"span">) { return <span className={cn("ml-auto text-xs text-muted-foreground", className)} {...props} /> } export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent, DropdownMenuShortcut, }components/ui/split-button.tsxsplit-button
components/ui/split-button.tsx"use client" import * as React from "react" import { ChevronDownIcon } from "lucide-react" import { cn } from "cn" import { Button, type ButtonProps } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" /* Split button: a main action plus a menu of related actions, joined in one shape. The leading button runs the action; the trailing one opens the menu. Same variants and sizes as Button. */ function SplitButton({ className, variant = "primary", size = "md", menuLabel = "More options", menu, children, ...props }: ButtonProps & { menu: React.ReactNode; menuLabel?: string }) { const iconSize = size === "sm" ? "icon-sm" : size === "lg" ? "icon-lg" : "icon" return ( <div data-slot="split-button" className={cn("inline-flex items-center gap-(--split-button-gap)", className)}> <Button variant={variant} size={size} className="rounded-e-(--split-button-inner-corner)" {...props}> {children} </Button> <DropdownMenu> <DropdownMenuTrigger render={<Button variant={variant} size={iconSize} aria-label={menuLabel} className="split-chevron rounded-s-(--split-button-inner-corner)" />} > <ChevronDownIcon /> </DropdownMenuTrigger> <DropdownMenuContent align="end">{menu}</DropdownMenuContent> </DropdownMenu> </div> ) } export { SplitButton }
Imports
What the examples on this page import:
import {
import { AppBar } from "@/components/ui/app-bar"
import { Badge } from "@/components/ui/badge"
import { Breadcrumb } from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import { DropdownMenuItem } from "@/components/ui/dropdown-menu"
import { Fab } from "@/components/ui/fab"
import { Navigation, NavigationItem } from "@/components/ui/navigation"
import { Pagination } from "@/components/ui/pagination"
import { SplitButton } from "@/components/ui/split-button"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "@/components/ui/toolbar"Anatomy
- 1Leading button · Runs the main action.
- 2Trailing button · Opens the menu; --split-button-inner-corner where they meet.
- 3Menu · Related actions.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant, size | as Button | "primary", "md" | Shared by both halves. |
menu | ReactNode | — | DropdownMenuItem children. |
menuLabel | string | "More options" | Label for the chevron. |
Tokens
Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.
| Token | Points to | Light | Dark |
|---|---|---|---|
--split-button-gap | var(--space-0-5) | 2px | same |
--split-button-inner-corner | var(--shape-xs) | 6px | same |
Motion
| Trigger | What happens | Tokens |
|---|---|---|
| Open | Chevron flips with a bounce; the menu grows from it. | --duration-medium, --ease-bounce |
Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.
Accessibility
- Two buttons: the action and the menu trigger, each labelled.
Usage
Do
- Use when one option is clearly the default.
Don’t
- Don't hide the main action in the menu.
Code
"use client"
import * as React from "react"
import { ChevronDownIcon } from "lucide-react"
import { cn } from "cn"
import { Button, type ButtonProps } from "@/components/ui/button"
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
/*
Split button: a main action plus a menu of related actions, joined in one
shape. The leading button runs the action; the trailing one opens the menu.
Same variants and sizes as Button.
*/
function SplitButton({
className,
variant = "primary",
size = "md",
menuLabel = "More options",
menu,
children,
...props
}: ButtonProps & { menu: React.ReactNode; menuLabel?: string }) {
const iconSize = size === "sm" ? "icon-sm" : size === "lg" ? "icon-lg" : "icon"
return (
<div data-slot="split-button" className={cn("inline-flex items-center gap-(--split-button-gap)", className)}>
<Button variant={variant} size={size} className="rounded-e-(--split-button-inner-corner)" {...props}>
{children}
</Button>
<DropdownMenu>
<DropdownMenuTrigger
render={<Button variant={variant} size={iconSize} aria-label={menuLabel} className="split-chevron rounded-s-(--split-button-inner-corner)" />}
>
<ChevronDownIcon />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">{menu}</DropdownMenuContent>
</DropdownMenu>
</div>
)
}
export { SplitButton }