# Splitter

Panels side by side with a handle between them that resizes them.

Panels side by side (or stacked) with a handle between each pair that resizes them: dragged by the pointer 1:1, stepped by the arrow keys. The handle at rest is the separator's 1px rule in the line colour, so a splitter reads like any divided surface; it darkens under a mouse and turns accent while dragged. An optional grip sits on the rule. Behaviour by Ark UI's splitter (Zag). Sizes are percentages; controlled or uncontrolled.

Kind: component · Category: Display · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `splitter` machine, through Ark UI

## Add

```bash
npx fndn add splitter
```

It writes the folder `splitter/` into the project's ui folder (`index.ts`, `splitter.tsx`, `Splitter.vue`, `Splitter.svelte`, `splitter.recipe.ts`). First time: [Installation](/installation.md).

## Usage

```tsx
import { Splitter } from "@/components/ui/splitter";
```

```vue
import { Splitter } from "@/components/ui/splitter";
```

```svelte
import { Splitter } from "$lib/components/ui/splitter";
```

## Parts

In the DOM the root carries `data-slot="splitter"` and each part `data-slot="splitter-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `splitter` |  | Ark's splitter root: a flex row (a column when vertical) as large as its container (the engine sets width and height to 100% and clips). Give it, or its parent, a height. No frame of its own: the caller frames it (a card, a window). |
| `panel` | `div` | `splitter-panel` | repeats | One region, sized by the engine (flex-grow from a zero basis, from its percentage), so it never pads itself. Scrolls its own content when it overflows (the engine's inline overflow: hidden is overridden) and hands the wheel on to the page at its ends. |
| `text` | `p` | `splitter-text` | optional, repeats | A panel's content when it is plain text: padded 12px, text.sm ink-2, wrapping anywhere; author text keeps its own direction. |
| `handle` | `div` | `splitter-handle` | repeats | Ark's resize trigger between two panels: role=separator, focusable, the 1px rule in color.line (1px wide in a row, 1px high in a column). Its hit area reaches 4px each side under a mouse (9px) and 20px each side on a coarse pointer (41px), without changing its look. Hovered by a mouse: ink-3; dragged: accent. The cursor is the engine's col-resize / row-resize; touch-action none, so a drag never scrolls the page. |
| `grip` | `div` | `splitter-grip` | optional | The optional grip (grip prop), Ark's resize trigger indicator: a 12×24 tab centred on the rule by flex centring (never a fractional translate) (24×12 in a column), surface with shadow.btn and radius.chip, holding the dots-six-vertical glyph at 10px in ink-3 (turned a quarter in a column). Decoration; the handle is what is dragged and focused. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `panels` | `{ id: string; content: node? (a string is padded text); minSize: number? (percent); maxSize: number? (percent); collapsible?: boolean; collapsedSize: number? (percent) }[]` |  | The panels in order, with their limits. Every pair gets a handle. |
| `size` | `number[]` |  | Bindable (React: `defaultSize` and `onSizeChange`; Vue: `v-model:size`; Svelte: `bind:size`). One percentage per panel, adding up to 100. Controlled: size with onSizeChange. Uncontrolled: defaultSize. Without either, the panels share the room equally. |
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | horizontal: panels side by side, the handles are vertical rules. vertical: panels stacked, the handles are horizontal rules. |
| `grip` | `boolean` | `false` | Show the grip on every handle. |
| `keyboardStep` | `number` | `1` | Percent an arrow key moves a handle; Shift + arrow moves 10. |
| `handleLabel` | `string` | `"Resize"` | Accessible name of every handle. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `sizeChange` | (size: number[]) while dragging and on every key |
| `sizeChangeEnd` | (size: number[]) when a drag or a key press ends |

## States

`hover`, `dragging`, `focus-visible`

## Keyboard and accessibility

Role: separator.

Keyboard:

- Tab moves to each handle in turn
- Arrow Left / Right (horizontal) or Up / Down (vertical) move the focused handle by keyboardStep percent; with Shift, 10. Right-to-left, Left and Right are mirrored (the engine's keys)
- Home / End: the panel before the handle shrinks to its minimum / grows to its maximum
- Enter collapses or expands a collapsible panel (the engine's key)
- F6 moves to the next handle (the engine's key)

Notes:

- Each handle is role=separator with aria-valuenow (the size of the panel before it), aria-valuemin, aria-valuemax, aria-orientation (perpendicular to the layout) and aria-controls naming both panels.
- Name the handles with handleLabel ("Resize" by default); give the panels their own headings when they have names.
- Resizing is never animated: the panels follow the pointer 1:1 and a key moves them at once.

## Motion

- panels: no transition; they follow the pointer 1:1 while dragged and change at once from the keyboard
- handle hover (a real pointer only): line → ink-3 over duration.fast; while dragged: accent at once; back to line over duration.fast
- grip: never moves on its own
- first paint: the panels are laid out at their given sizes from the first frame; a collapsible panel given its collapsed size is shut from the first frame (its minSize only applies once it is open; React renders a frame before the engine resolves the sizes, so its adapter holds the collapsed minimum meanwhile)

## Tokens

`color.line`, `color.ink-2`, `color.ink-3`, `color.accent`, `color.surface`, `shadow.btn`, `radius.chip`, `text.sm`, `duration.fast`

## Examples

### Files beside the editor

React · `files-and-editor.tsx`

```tsx
import { Splitter } from "@/components/ui/splitter";

const files = ["deliver.ts", "retry.ts", "verify.ts", "webhooks.test.ts"];
const code = [
  "retry(() => post(event), {",
  "  attempts: 5,",
  "  backoff: \"exponential\",",
  "});",
];

export default function FilesAndEditor() {
  return (
    <div className="h-[136px] w-full">
      <Splitter
        defaultSize={[30, 70]}
        panels={[
          {
            id: "files",
            minSize: 25,
            content: (
              <ul className="flex flex-col gap-0.5 p-1.5 text-sm text-ink-2" aria-label="Files">
                {files.map((file) => (
                  <li key={file} className={`truncate rounded-control px-2 py-1 ${file === "deliver.ts" ? "bg-hover text-ink" : ""}`}>{file}</li>
                ))}
              </ul>
            ),
          },
          {
            id: "editor",
            minSize: 40,
            content: <pre className="p-3 font-mono text-xs leading-relaxed text-ink">{code.join("\n")}</pre>,
          },
        ]}
      />
    </div>
  );
}
```

Vue · `files-and-editor.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Splitter } from "@/components/ui/splitter";

const files = ["deliver.ts", "retry.ts", "verify.ts", "webhooks.test.ts"];
const code = [
  "retry(() => post(event), {",
  "  attempts: 5,",
  "  backoff: \"exponential\",",
  "});",
];
const size = ref([30, 70]);
</script>

<template>
  <div class="h-[136px] w-full">
    <Splitter
      v-model:size="size"
      :panels="[
        { id: 'files', minSize: 25 },
        { id: 'editor', minSize: 40 },
      ]"
    >
      <template #panel="{ panel }">
        <ul v-if="panel.id === 'files'" class="flex flex-col gap-0.5 p-1.5 text-sm text-ink-2" aria-label="Files">
          <li v-for="file in files" :key="file" :class="`truncate rounded-control px-2 py-1 ${file === 'deliver.ts' ? 'bg-hover text-ink' : ''}`">{{ file }}</li>
        </ul>
        <pre v-else class="p-3 font-mono text-xs leading-relaxed text-ink">{{ code.join("\n") }}</pre>
      </template>
    </Splitter>
  </div>
</template>
```

Svelte · `files-and-editor.svelte`

```svelte
<script lang="ts">
  import { Splitter } from "$lib/components/ui/splitter";

  const files = ["deliver.ts", "retry.ts", "verify.ts", "webhooks.test.ts"];
  const code = [
    "retry(() => post(event), {",
    "  attempts: 5,",
    "  backoff: \"exponential\",",
    "});",
  ];
  let size = $state([30, 70]);
</script>

<div class="h-[136px] w-full">
  <Splitter
    bind:size
    panels={[
      { id: "files", minSize: 25 },
      { id: "editor", minSize: 40 },
    ]}
  >
    {#snippet panel({ panel: item })}
      {#if item.id === "files"}
        <ul class="flex flex-col gap-0.5 p-1.5 text-sm text-ink-2" aria-label="Files">
          {#each files as file (file)}
            <li class={`truncate rounded-control px-2 py-1 ${file === "deliver.ts" ? "bg-hover text-ink" : ""}`}>{file}</li>
          {/each}
        </ul>
      {:else}
        <pre class="p-3 font-mono text-xs leading-relaxed text-ink">{code.join("\n")}</pre>
      {/if}
    {/snippet}
  </Splitter>
</div>
```

### Editor above the terminal

React · `editor-and-terminal.tsx`

```tsx
import { Splitter } from "@/components/ui/splitter";

const code = [
  "test(\"retries a failed delivery\", async () => {",
  "  server.failNext(2);",
  "  await deliver(event);",
  "  expect(server.calls).toBe(3);",
  "});",
];
const output = ["$ pnpm test webhooks", "✓ webhooks.test.ts (12 tests) 840ms", "Tests  12 passed (12)"];

export default function EditorAndTerminal() {
  return (
    <div className="h-64 w-full max-w-md rounded-card bg-surface shadow-card">
      <Splitter
        orientation="vertical"
        grip
        defaultSize={[60, 40]}
        panels={[
          { id: "editor", minSize: 25, content: <pre className="p-3 font-mono text-xs leading-relaxed text-ink">{code.join("\n")}</pre> },
          { id: "terminal", minSize: 20, content: <pre className="p-3 font-mono text-xs leading-relaxed text-ink-2">{output.join("\n")}</pre> },
        ]}
      />
    </div>
  );
}
```

Vue · `editor-and-terminal.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Splitter } from "@/components/ui/splitter";

const code = [
  "test(\"retries a failed delivery\", async () => {",
  "  server.failNext(2);",
  "  await deliver(event);",
  "  expect(server.calls).toBe(3);",
  "});",
];
const output = ["$ pnpm test webhooks", "✓ webhooks.test.ts (12 tests) 840ms", "Tests  12 passed (12)"];
const size = ref([60, 40]);
</script>

<template>
  <div class="h-64 w-full max-w-md rounded-card bg-surface shadow-card">
    <Splitter
      v-model:size="size"
      orientation="vertical"
      grip
      :panels="[
        { id: 'editor', minSize: 25 },
        { id: 'terminal', minSize: 20 },
      ]"
    >
      <template #panel="{ panel }">
        <pre v-if="panel.id === 'editor'" class="p-3 font-mono text-xs leading-relaxed text-ink">{{ code.join("\n") }}</pre>
        <pre v-else class="p-3 font-mono text-xs leading-relaxed text-ink-2">{{ output.join("\n") }}</pre>
      </template>
    </Splitter>
  </div>
</template>
```

Svelte · `editor-and-terminal.svelte`

```svelte
<script lang="ts">
  import { Splitter } from "$lib/components/ui/splitter";

  const code = [
    "test(\"retries a failed delivery\", async () => {",
    "  server.failNext(2);",
    "  await deliver(event);",
    "  expect(server.calls).toBe(3);",
    "});",
  ];
  const output = ["$ pnpm test webhooks", "✓ webhooks.test.ts (12 tests) 840ms", "Tests  12 passed (12)"];
  let size = $state([60, 40]);
</script>

<div class="h-64 w-full max-w-md rounded-card bg-surface shadow-card">
  <Splitter
    bind:size
    orientation="vertical"
    grip
    panels={[
      { id: "editor", minSize: 25 },
      { id: "terminal", minSize: 20 },
    ]}
  >
    {#snippet panel({ panel: item })}
      {#if item.id === "editor"}
        <pre class="p-3 font-mono text-xs leading-relaxed text-ink">{code.join("\n")}</pre>
      {:else}
        <pre class="p-3 font-mono text-xs leading-relaxed text-ink-2">{output.join("\n")}</pre>
      {/if}
    {/snippet}
  </Splitter>
</div>
```

### Three panes with a reset

React · `review-layout.tsx`

```tsx
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Splitter } from "@/components/ui/splitter";

const panels = [
  { id: "pull-request", content: "#482 Add retry to webhook delivery. Daniel Okafor wants to merge 3 commits into main.", minSize: 20 },
  { id: "change", content: "src/webhooks/deliver.ts, +4 −1: a failed delivery now retries five times with exponential backoff.", minSize: 25 },
  { id: "checks", content: "Build passed, 12 tests passed, preview ready.", minSize: 20 },
];
const initial = [30, 40, 30];

export default function ReviewLayout() {
  const [size, setSize] = useState(initial);
  return (
    <div className="flex w-full max-w-xl flex-col items-start gap-3">
      <div className="h-44 w-full rounded-card bg-surface shadow-card">
        <Splitter grip panels={panels} size={size} onSizeChange={setSize} />
      </div>
      <Button size="sm" onClick={() => setSize(initial)}>Reset layout</Button>
    </div>
  );
}
```

Vue · `review-layout.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@/components/ui/button";
import { Splitter } from "@/components/ui/splitter";

const panels = [
  { id: "pull-request", content: "#482 Add retry to webhook delivery. Daniel Okafor wants to merge 3 commits into main.", minSize: 20 },
  { id: "change", content: "src/webhooks/deliver.ts, +4 −1: a failed delivery now retries five times with exponential backoff.", minSize: 25 },
  { id: "checks", content: "Build passed, 12 tests passed, preview ready.", minSize: 20 },
];
const initial = [30, 40, 30];
const size = ref(initial);
</script>

<template>
  <div class="flex w-full max-w-xl flex-col items-start gap-3">
    <div class="h-44 w-full rounded-card bg-surface shadow-card">
      <Splitter v-model:size="size" grip :panels="panels" />
    </div>
    <Button size="sm" @click="size = initial">Reset layout</Button>
  </div>
</template>
```

Svelte · `review-layout.svelte`

```svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button";
  import { Splitter } from "$lib/components/ui/splitter";

  const panels = [
    { id: "pull-request", content: "#482 Add retry to webhook delivery. Daniel Okafor wants to merge 3 commits into main.", minSize: 20 },
    { id: "change", content: "src/webhooks/deliver.ts, +4 −1: a failed delivery now retries five times with exponential backoff.", minSize: 25 },
    { id: "checks", content: "Build passed, 12 tests passed, preview ready.", minSize: 20 },
  ];
  const initial = [30, 40, 30];
  let size = $state(initial);
</script>

<div class="flex w-full max-w-xl flex-col items-start gap-3">
  <div class="h-44 w-full rounded-card bg-surface shadow-card">
    <Splitter bind:size grip {panels} />
  </div>
  <Button size="sm" onclick={() => (size = initial)}>Reset layout</Button>
</div>
```

## Recipe

`splitter.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* splitter — panels with a handle between each pair that resizes them (Ark UI splitter).
 *
 * The engine lays the root out (flex row, or column when vertical; width and height 100%; it
 * clips) and sizes every panel (flex-basis from its percentage), so nothing here sizes a panel.
 * The handle at rest is the separator's rule (1px, color.line); a mouse over it darkens it to
 * ink-3 (over duration.fast) and a drag turns it accent at once, both as colour only. Panels never animate: they follow the
 * pointer 1:1 and a key moves them at once.
 *
 * Touch: the handle's hit area is a ::after that reaches 4px each side under a mouse (9px) and
 * 20px each side on a coarse pointer (41px), without changing its look; the handle is positioned
 * and the panels are not, so the hit area sits above them. The engine puts touch-action: none on
 * the handle, so a drag never scrolls the page.
 *
 * The optional grip is centred on the rule by the handle's flex centring (an overflowing flex item
 * overflows both sides equally), never by a fractional translate.
 *
 * The engine sizes panels by flex-grow from a zero basis and puts overflow: hidden on them inline,
 * so a panel never pads itself (padding would skew the proportions) and the scroll is overridden
 * (overflow-auto!). A panel of plain text holds it in the text part, which pads it. */
export const splitter = tv({
  slots: {
    base: "min-w-0 min-h-0",
    /* a panel scrolls its own content and hands the wheel on to the page at its ends */
    panel: "min-w-0 min-h-0 overflow-auto!",
    text: "m-0 p-3 text-sm leading-normal text-ink-2 wrap-anywhere [unicode-bidi:plaintext]",
    handle: [
      "relative z-1 flex items-center justify-center shrink-0 self-stretch bg-line",
      "motion-colors-fast",
      /* hover fades in (duration.fast); a drag turns it accent at once (it answers the press), and
       * releasing fades back */
      "hover:bg-ink-3 data-dragging:bg-accent data-dragging:duration-0",
      "after:content-[''] after:absolute",
      "data-disabled:pointer-events-none",
    ],
    grip: "z-1 shrink-0 flex items-center justify-center rounded-chip bg-surface shadow-btn text-[10px] text-ink-3 [&>svg]:size-[1em]",
  },
  variants: {
    orientation: {
      /* panels side by side: the handle is a vertical rule */
      horizontal: {
        handle: "w-px after:inset-y-0 after:-inset-x-1 pointer-coarse:after:-inset-x-5",
        grip: "w-3 h-6",
      },
      /* panels stacked: the handle is a horizontal rule; the grip's dots lie down */
      vertical: {
        handle: "h-px after:inset-x-0 after:-inset-y-1 pointer-coarse:after:-inset-y-5",
        grip: "w-6 h-3 [&>svg]:rotate-90",
      },
    },
  },
  defaultVariants: { orientation: "horizontal" },
});

export type SplitterRecipeProps = VariantProps<typeof splitter>;
```
