# Split Button

A connected primary action and secondary action or menu trigger.

A split button lets someone perform a primary action immediately or choose a closely related alternative from a secondary action, usually a dropdown menu.

```tsx
import { CaretDownIcon } from "@phosphor-icons/react";
import { Button, DropdownMenu, IconButton, SplitButton } from "@zentara-co/zenos-ui";

function SplitButtonExample() {
  return (
    <SplitButton label="Publish options">
      <Button variant="primary">Publish</Button>
      <DropdownMenu.Root>
        <DropdownMenu.Trigger
          render={<IconButton aria-label="More publish options" variant="primary" />}
        >
          <CaretDownIcon />
        </DropdownMenu.Trigger>
        <DropdownMenu.Content align="end">
          <DropdownMenu.Item>Publish and notify</DropdownMenu.Item>
          <DropdownMenu.Item>Schedule publication</DropdownMenu.Item>
        </DropdownMenu.Content>
      </DropdownMenu.Root>
    </SplitButton>
  );
}
```

## Import

```tsx
import { SplitButton } from "@zentara-co/zenos-ui";
```

## Composition

Place the primary `Button` first and an `IconButton` or menu trigger second. Apply the same visual `variant` to both actions. `SplitButton` connects their borders and corners without hiding either action from the native tab order.

Use a specific accessible label for the secondary action, such as “More publish options,” rather than repeating the primary label.

## Shared and custom variants

Set `variant` on `SplitButton` to keep both actions consistent without repeating the prop. `variantClassName` defines a consumer-owned appearance and is inherited by actions that do not override the group variant.

```tsx
import { CaretDownIcon } from "@phosphor-icons/react";
import { Button, IconButton, SplitButton } from "@zentara-co/zenos-ui";

const campaignSplitButtonVariant =
  "bg-background-accent-purple-bolder-default text-text-contrary hover:bg-background-accent-purple-bolder-hover active:bg-background-accent-purple-bolder-pressed";

function SplitButtonCustomVariantExample() {
  return (
    <SplitButton
      label="Campaign options"
      variant="campaign"
      variantClassName={campaignSplitButtonVariant}
    >
      <Button>Launch campaign</Button>
      <IconButton aria-label="More campaign options">
        <CaretDownIcon />
      </IconButton>
    </SplitButton>
  );
}
```

## Sizes

The split button passes its `size` to buttons and icon buttons that do not set their own size.

```tsx
import { CaretDownIcon } from "@phosphor-icons/react";
import { Button, IconButton, SplitButton, Stack } from "@zentara-co/zenos-ui";

function SplitButtonSizesExample() {
  return (
    <Stack direction="row" gap="4" align="center" wrap="wrap">
      {(["sm", "md", "lg"] as const).map((size) => (
        <SplitButton key={size} label={`${size} create options`} size={size}>
          <Button variant="primary">Create</Button>
          <IconButton aria-label={`More ${size} create options`} variant="primary">
            <CaretDownIcon />
          </IconButton>
        </SplitButton>
      ))}
    </Stack>
  );
}
```

## Motion

Pressed scaling is disabled by default for `Button` and `IconButton` children. Scaling individual halves can make the connected control look as though its border is separating. The pressed color still provides immediate feedback.

An individual action can opt back into motion when the composition calls for it:

```tsx
<SplitButton label="Create options">
  <Button disableMotion={false}>Create</Button>
  <IconButton aria-label="More create options" disableMotion={false}>
    <CaretDownIcon />
  </IconButton>
</SplitButton>
```

## Disabled state

Set `disabled` on the split button when neither action is available. Loading remains a state of an individual action.

```tsx
import { CaretDownIcon } from "@phosphor-icons/react";
import { Button, IconButton, SplitButton, Stack } from "@zentara-co/zenos-ui";

function SplitButtonStatesExample() {
  return (
    <Stack direction="row" gap="4" align="center" wrap="wrap">
      <SplitButton label="Available save options">
        <Button variant="primary">Save</Button>
        <IconButton aria-label="More save options" variant="primary">
          <CaretDownIcon />
        </IconButton>
      </SplitButton>
      <SplitButton label="Disabled save options" disabled>
        <Button variant="primary">Save</Button>
        <IconButton aria-label="More disabled save options" variant="primary">
          <CaretDownIcon />
        </IconButton>
      </SplitButton>
    </Stack>
  );
}
```

## Sizes

sm, md, lg

## Anatomy

```text
SplitButton.Root
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant | ButtonVariant \| custom string | default | Visual treatment inherited by actions without an override. |
| variantClassName | string | — | Variant classes inherited by actions using the group variant. |
| size | sm \| md \| lg | md | Size inherited by split actions. |
| disabled | boolean | false | Disables both split actions. |
| Button / IconButton.disableMotion | boolean | true inside SplitButton | Pressed motion is disabled for connected actions by default. Set false on an individual action to enable it. |
| label | string | — | Accessible group name used when aria-label is omitted. |
| aria-label | string | — | Accessible group name. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

`SplitButton` renders an accessible group. The primary and secondary actions remain separate native controls and separate tab stops. Preserve the dropdown menu's own trigger, focus, and keyboard behavior when using one as the secondary action.

Source: https://zenos-ui.pages.dev/components/split-button/