# Split Button

An outline button joined to a chevron that opens more options, split by an inset seam. Each half hovers, presses and takes focus on its own; the chevron stays shaded while its menu is open.

- Beta: ready to use; its API can still change in a minor release.
- Category: Actions

```tsx
import { SplitButton, SplitButtonAction, SplitButtonMenu } from "@leap-crm/design-system";
```

## Best practices

- Do: Put the common action in `SplitButtonAction` and its variants in the menu, like Add with more ways to add, so the usual case is one click.
- Do: Pass `SplitButtonMenu` to a menu trigger's `render`, so the menu opens from the chevron and the chevron stays shaded while it is open.
- Do: Name both parts: `aria-label` on `SplitButton` for the pair, like Add, and on `SplitButtonMenu` for what the chevron offers, like More ways to add.
- Do: Size it as you would a `Button` beside it: `md` by default, `sm` in toolbars and columns, `xs` in dense rows like the conflict check. In an `ActionRow` it takes the row's size.
- Don't: Stretch it to fill a container. Like a `Button` it is as wide as its label; in a narrow column put it in an `ActionRow`, which shares the width.
- Don't: Use it when the menu holds unrelated actions or no option is more common than the rest. Use a `DropdownMenu` opened from a `Button` or `IconButton`.

## Keyboard

| Keys | What they do |
| --- | --- |
| Tab | Moves from the main button to the chevron: each half takes focus on its own. |
| Enter, Space | Press the focused half. |

## Related

- [Button](./button.md)
- [Dropdown Menu](./dropdown-menu.md)
- [Button Group](./button-group.md)

## Examples

What the examples import:

```tsx
import { MessageSquarePlus, PhoneCall, Plus } from "lucide-react";
import { Fragment } from "react";
import { SplitButton, SplitButtonAction, SplitButtonMenu } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const sizes = ["lg", "md", "sm", "xs"] as const;
```

### Sizes

Button's heights: lg 40, md 36 (the default), sm 32, xs 28. The chevron half is 4 px narrower than the height, so xs keeps a 24 px target.

```tsx
<div className="grid grid-cols-[auto_auto] items-center justify-start justify-items-start gap-x-6 gap-y-3">
  {sizes.map(size => (
    <Fragment key={size}>
      <span className="text-small text-neutral-text-muted">{size}</span>
      <SplitButton aria-label="Add" size={size}>
        <SplitButtonAction icon={<Plus />}>Add</SplitButtonAction>
        <SplitButtonMenu aria-label="More ways to add" />
      </SplitButton>
    </Fragment>
  ))}
</div>
```

### Open

While its menu is open the chevron half keeps the hover shade. A menu trigger sets aria-expanded on it.

```tsx
<SplitButton aria-label="Log interaction" size="sm">
  <SplitButtonAction icon={<PhoneCall />}>
    Interaction
  </SplitButtonAction>
  <SplitButtonMenu aria-label="More interactions" aria-expanded />
</SplitButton>
```

### Disabled

```tsx
<SplitButton aria-label="Add note" size="sm">
  <SplitButtonAction icon={<MessageSquarePlus />} disabled>
    Note
  </SplitButtonAction>
  <SplitButtonMenu aria-label="More note options" disabled />
</SplitButton>
```

## Props

SplitButtonAction takes Button's props (icon, loading, onClick, disabled). SplitButtonMenu takes Button's props too: pass it to a menu trigger's render.

### SplitButton

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `ButtonSize` |  | Button's sizes: xs 28 · sm 32 · md 36 (the default) · lg 40. Inside an ActionRow it takes the row's. |
| `aria-label` | `string` |  | Names the pair for screen readers, like "Add". |
| `children` (required) | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SplitButtonAction

No props of its own.

### SplitButtonMenu

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `aria-label` (required) | `string` |  | What the chevron offers, like "More ways to add". |
