Splitter

Resizable split pane layout

Usage

Splitter is a resizable split pane layout. Double-click a handle to restore its two panes to their default ratio, set resetOnDoubleClick={false} to disable it:

First pane
Second pane
Orientation
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter h={200}>
      <Splitter.Pane defaultSize={50} min={20} bg="blue">
        First pane
      </Splitter.Pane>
      <Splitter.Pane defaultSize={50} min={20} bg="teal">
        Second pane
      </Splitter.Pane>
    </Splitter>
  );
}

CSS units

defaultSize, min and max props of Splitter.Pane accept numbers, percentages and CSS units:

  • A number or a % string is a flexible size, the pane shares the leftover space with other flexible panes
  • A px or rem string is a fixed size, the pane keeps it when the container is resized

sizes and onSizeChange use the unit the pane was declared with:

Fixed 240px sidebar
Flexible content
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter h={200}>
      <Splitter.Pane defaultSize="240px" min="160px" max="50%" bg="blue">
        Fixed 240px sidebar
      </Splitter.Pane>
      <Splitter.Pane defaultSize={100} bg="teal">
        Flexible content
      </Splitter.Pane>
    </Splitter>
  );
}

Vertical orientation

Set orientation="vertical" to split panes vertically:

Top pane
Bottom pane
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter orientation="vertical" h={300}>
      <Splitter.Pane defaultSize={60} min={20} bg="blue">
        Top pane
      </Splitter.Pane>
      <Splitter.Pane defaultSize={40} min={20} bg="teal">
        Bottom pane
      </Splitter.Pane>
    </Splitter>
  );
}

Collapsible panes

Set collapsible prop on Splitter.Pane to collapse the pane when it is dragged past its minimum size:

Collapsible sidebar
Main content
import { useRef } from 'react';
import { Button, Group, Splitter } from '@mantine/core';
import { UseSplitterReturnValue } from '@mantine/hooks';

function Demo() {
  const splitterRef = useRef<UseSplitterReturnValue>(null);

  return (
    <>
      <Splitter splitterRef={splitterRef} h={200}>
        <Splitter.Pane defaultSize={30} min={20} collapsible bg="blue">
          Collapsible sidebar
        </Splitter.Pane>
        <Splitter.Pane defaultSize={70} min={30} bg="teal">
          Main content
        </Splitter.Pane>
      </Splitter>
      <Group mt="md">
        <Button size="xs" onClick={() => splitterRef.current?.toggleCollapse(0)}>
          Toggle sidebar
        </Button>
      </Group>
    </>
  );
}

Controlled

Use sizes and onSizeChange props to control pane sizes. sizes must have one value per pane, update it when you add or remove a pane:

Panel A (50%)
Panel B (50%)

Current sizes: [50, 50]

import { useState } from 'react';
import { Button, Group, Splitter, Text } from '@mantine/core';

function Demo() {
  const [sizes, setSizes] = useState([50, 50]);

  return (
    <>
      <Splitter sizes={sizes} onSizeChange={(next) => setSizes(next.map(Number))} h={200}>
        <Splitter.Pane defaultSize={50} min={20} bg="blue">
          Panel A ({Math.round(sizes[0])}%)
        </Splitter.Pane>
        <Splitter.Pane defaultSize={50} min={20} bg="teal">
          Panel B ({Math.round(sizes[1])}%)
        </Splitter.Pane>
      </Splitter>
      <Text size="sm" mt="sm">
        Current sizes: [{sizes.map((s) => Math.round(s)).join(', ')}]
      </Text>
      <Group mt="xs">
        <Button size="xs" onClick={() => setSizes([30, 70])}>30 / 70</Button>
        <Button size="xs" onClick={() => setSizes([50, 50])}>50 / 50</Button>
        <Button size="xs" onClick={() => setSizes([70, 30])}>70 / 30</Button>
      </Group>
    </>
  );
}

Multiple panes

Splitter supports any number of panes. Handles are automatically rendered between panes:

First
Second
Third
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter h={200}>
      <Splitter.Pane defaultSize={25} min={10} bg="blue">
        First
      </Splitter.Pane>
      <Splitter.Pane defaultSize={50} min={10} bg="teal">
        Second
      </Splitter.Pane>
      <Splitter.Pane defaultSize={25} min={10} bg="grape">
        Third
      </Splitter.Pane>
    </Splitter>
  );
}

Nested splitters

You can nest Splitter components to create complex layouts:

Sidebar
Editor
Terminal
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter h={350}>
      <Splitter.Pane defaultSize={30} min={15} bg="blue">
        Sidebar
      </Splitter.Pane>
      <Splitter.Pane defaultSize={70} min={30}>
        <Splitter orientation="vertical" h="100%">
          <Splitter.Pane defaultSize={60} min={20} bg="teal">
            Editor
          </Splitter.Pane>
          <Splitter.Pane defaultSize={40} min={20} bg="grape">
            Terminal
          </Splitter.Pane>
        </Splitter>
      </Splitter.Pane>
    </Splitter>
  );
}

Redistribute

Set redistribute prop to control how space is borrowed from non-adjacent panes when the immediate neighbor has reached its min or max size:

Panel A
Panel B
Panel C
Panel D
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter redistribute="nearest" h={200}>
      <Splitter.Pane defaultSize={25} min={10} bg="blue">
        Panel A
      </Splitter.Pane>
      <Splitter.Pane defaultSize={25} min={10} bg="teal">
        Panel B
      </Splitter.Pane>
      <Splitter.Pane defaultSize={25} min={10} bg="grape">
        Panel C
      </Splitter.Pane>
      <Splitter.Pane defaultSize={25} min={10} bg="orange">
        Panel D
      </Splitter.Pane>
    </Splitter>
  );
}

Line size

Set lineSize prop to change the thickness of the separator line between panes:

First pane
Second pane
Line size
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter h={200}>
      <Splitter.Pane defaultSize={50} min={20} bg="blue">
        First pane
      </Splitter.Pane>
      <Splitter.Pane defaultSize={50} min={20} bg="teal">
        Second pane
      </Splitter.Pane>
    </Splitter>
  );
}

Without handle

Set withHandle={false} to hide the thumb with grip icon. The separator line between panes is still visible and draggable:

First pane
Second pane
import { Splitter } from '@mantine/core';

function Demo() {
  return (
    <Splitter withHandle={false} h={200}>
      <Splitter.Pane defaultSize={50} min={20} bg="blue">
        First pane
      </Splitter.Pane>
      <Splitter.Pane defaultSize={50} min={20} bg="teal">
        Second pane
      </Splitter.Pane>
    </Splitter>
  );
}

Handle props

Use getHandleProps(index) to customize individual separators, identified by their zero-based data-index attribute. Set disabled to prevent dragging, keyboard resizing and double-click reset. Set withHandle to override thumb visibility for that separator:

First pane
Second pane
Third pane
import { useState } from 'react';
import { Checkbox, Splitter, Stack } from '@mantine/core';

function Demo() {
  const [locked, setLocked] = useState(true);

  return (
    <Stack>
      <Checkbox
        label="Lock first separator"
        checked={locked}
        onChange={(event) => setLocked(event.currentTarget.checked)}
      />
      <Splitter
        h={200}
        getHandleProps={(index) => ({
          disabled: index === 0 && locked,
          withHandle: index === 0 ? !locked : true,
          mod: { locked: index === 0 && locked },
          'aria-label': index === 0 ? 'Resize first pane' : 'Resize second pane',
        })}
      >
        <Splitter.Pane defaultSize={30} min={15} bg="blue" c="white" p="md">
          First pane
        </Splitter.Pane>
        <Splitter.Pane defaultSize={40} min={15} bg="teal" c="white" p="md">
          Second pane
        </Splitter.Pane>
        <Splitter.Pane defaultSize={30} min={15} bg="grape" c="white" p="md">
          Third pane
        </Splitter.Pane>
      </Splitter>
    </Stack>
  );
}

Imperative API

Use splitterRef prop to collapse, expand and resize panes programmatically:

import { useRef } from 'react';
import { Splitter } from '@mantine/core';
import { UseSplitterReturnValue } from '@mantine/hooks';

function Demo() {
  const splitterRef = useRef<UseSplitterReturnValue>(null);

  return (
    <>
      <button onClick={() => splitterRef.current?.collapse(0)}>
        Collapse first pane
      </button>
      <Splitter splitterRef={splitterRef}>
        <Splitter.Pane defaultSize={50} min={20} collapsible>
          First pane
        </Splitter.Pane>
        <Splitter.Pane defaultSize={50} min={20}>
          Second pane
        </Splitter.Pane>
      </Splitter>
    </>
  );
}

Wrap Splitter.Pane

Splitter.Pane must be a direct child of Splitter, wrapping it in another component is not supported:

import { Splitter } from '@mantine/core';

// This will not work – wrapped pane will not be recognized
function WillNotWork() {
  return (
    <Splitter.Pane defaultSize={50} min={20}>
      This part will not render correctly
    </Splitter.Pane>
  );
}

// Create a separate component for pane content instead
function PaneContent() {
  return <div>This will work as expected!</div>;
}

function Demo() {
  return (
    <Splitter h={200}>
      <Splitter.Pane defaultSize={50} min={20}>
        First pane
      </Splitter.Pane>
      {/* Do not wrap Splitter.Pane in another component */}
      {/* <WillNotWork /> */}
      <Splitter.Pane defaultSize={50} min={20}>
        <PaneContent />
      </Splitter.Pane>
    </Splitter>
  );
}

use-splitter hook

Splitter is built on top of the use-splitter hook. Use the hook directly when you need full control over the layout and styling.