# Split button

One control with two parts: the main part runs the best move, its chevron opens a menu of the others.

Live variants: https://design.arcadia.is/components/split-button

```tsx
import { SplitButton } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import {
  MenuContent, MenuRadioGroup, MenuRadioItem, SplitButton,
} from "@arcadia/ui";

function Demo() {
  const [branch, setBranch] = useState("main");
  const [published, setPublished] = useState("");
  return (
    <div {...sx("cmp-bar", cmp.bar)}>
      <SplitButton
        variant="primary"
        menuLabel="Publish to branch"
        hold={false}
        menu={
          <MenuContent align="end" aria-label="Publish to branch">
            <MenuRadioGroup value={branch} onValueChange={setBranch}>
              <MenuRadioItem value="main">main</MenuRadioItem>
              <MenuRadioItem value="preview">preview</MenuRadioItem>
            </MenuRadioGroup>
          </MenuContent>
        }
        onClick={() => setPublished(branch)}
      >
        Publish to {branch}
      </SplitButton>
      <span {...sx("cmp-result", cmp.result)} role="status">{published ? "Published to " + published : "Release notes draft"}</span>
    </div>
  );
}
```

## Accessibility

Two native `<button>`s in reading order. The main part is named by its label; the chevron by `menuLabel`, with `aria-haspopup` and `aria-expanded`, and focus moves into the menu and back. Standing alone, the chevron is one button named by the label it shows.

A `hint` is drawn only and becomes `aria-keyshortcuts` on the main part; binding the key is yours. `busy` sets `aria-busy` on the main part and blocks both parts without dropping focus.

- Enter + Space: On the main part, run its move
- Enter + Space + ↓: On the chevron, open the menu
- Esc: Close the menu and return focus

## API reference

### SplitButton

- `onClick` (`(e: MouseEvent<HTMLButtonElement>) => void`)
- `menuLabel` (`string`, required): The chevron's accessible name, and its label standing alone.
- `menu` (`ReactNode`, required): The `MenuContent` the chevron opens.
- `variant` (`"primary" | "secondary" | "ghost" | "text"`, default `"secondary"`)
- `size` (`"xs" | "sm"`, default `"sm"`)
- `hint` (`ShortcutSpec | ReactElement`): A key hint on the main part.
- `collapse` (`"auto" | "menu"`, default `"auto"`): `auto`: the chevron stands alone when the split doesn't fit. `menu`: always.
- `busy` (`boolean`, default `false`): The main part keeps its width, a spinner takes the chevron's place, both parts are inert.
- `disabled` (`boolean`, default `false`)
- `hold` (`boolean`, default `true`): The label and its action hold while the pointer is on the control or the menu is open.
- `open` (`boolean`)
- `defaultOpen` (`boolean`, default `false`)
- `onOpenChange` (`(open: boolean, details: OpenChangeDetails) => void`)
- `rootStyle` (`RootStyle`): A component's typed override prop: `Layout` and its documented knobs, each the references it takes or another kit knob of its kind; anything else is a type error at the call site (STYLEX.md).
- `children` (`ReactNode`, required): The main part's label: whole or gone, never faded.

Rest props go to `<span>` props.
