Splitter

A component that divides your interface into resizable sections

Loading...

Anatomy

<Splitter.Root>
  <Splitter.Panel />
  <Splitter.ResizeTrigger>
    <Splitter.ResizeTriggerIndicator />
  </Splitter.ResizeTrigger>
  <Splitter.Panel />
</Splitter.Root>

Examples

Context

Use Splitter.Context or the useSplitterContext hook to resize panels programmatically.

Vertical

Set orientation="vertical" for a vertical splitter.

Collapsible Panels

Set collapsible on a panel to let it collapse. collapsedSize sets its collapsed size. This suits sidebar layouts.

Multiple Panels

Root Provider

Use RootProvider with the useSplitter hook to access the state and methods from outside the component.

Resize Indicator

Splitter.ResizeTriggerIndicator shows an indicator on the resize handle.

Dynamic Collapsible

Call collapsePanel() and expandPanel() based on viewport size, for example to collapse a sidebar on small screens.

Nested

Nest splitters for grid-like layouts. Share a registry from Splitter.createRegistry() between them to drag both at points where horizontal and vertical splitters meet.

API Reference

Props

Root

Defines the <div> element.

AttributeDefaultType
panels
PanelData[]

The size constraints of the panels.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
defaultSize
PanelSize[]

The initial size of the panels when rendered. Use when you don't need to control the size of the panels.

disabled
boolean

Whether resizing is disabled for the whole splitter

id
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the splitter. Useful for composition.

keyboardResizeBy1
number

The percentage to resize the panel by when an arrow key is pressed.

nonce
string

The nonce for the injected splitter cursor stylesheet.

onCollapse
(details: ExpandCollapseDetails) => void

Function called when a panel is collapsed.

onExpand
(details: ExpandCollapseDetails) => void

Function called when a panel is expanded.

onResize
(details: ResizeDetails) => void

Function called when the splitter is resized.

onResizeEnd
(details: ResizeEndDetails) => void

Function called when the splitter resize ends.

onResizeStart
() => void

Function called when the splitter resize starts.

orientation'horizontal'
'horizontal' | 'vertical'

The orientation of the splitter. Can be `horizontal` or `vertical`

registry
SplitterRegistry

The splitter registry to use for multi-drag support. When provided, enables dragging at the intersection of multiple splitters.

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

size
PanelSize[]

The controlled size data of the panels

AttributeDescription
[data-splitter-root]<uid>
[data-orientation]The orientation of the splitter
[data-dragging]Present when in the dragging state

Panel

Defines the <div> element.

AttributeDefaultType
id
string

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-splitter-panel]<uid>
[data-orientation]The orientation of the panel
[data-dragging]Present when in the dragging state
[data-id]
[data-index]The index of the item

Registry

PropDefaultType
hitAreaMargins
HitAreaMargins

The hit area margins for resize handles. Larger margins make it easier to grab handles, especially on touch devices.

nonce
string

The nonce for the injected cursor stylesheet (for CSP compliance).

ResizeTriggerIndicator

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

ResizeTrigger

Defines the <button> element.

AttributeDefaultType
id
ResizeTriggerId

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
disabled
boolean

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<SplitterResizeTriggerState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-splitter-resize-trigger]<uid>
[data-id]
[data-orientation]The orientation of the resizetrigger
[data-focus]Present when focused
[data-dragging]Present when in the dragging state
[data-disabled]Present when disabled

RootProvider

Defines the <div> element.

AttributeDefaultType
value
UseSplitterReturn

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Context

API

PropertyType
dragging
boolean

Whether the splitter is currently being resized.

orientation
"horizontal" | "vertical"

The orientation of the splitter.

getSizes
() => number[]

Returns the current sizes of the panels.

setSizes
(size: PanelSize[]) => void

Sets the sizes of the panels.

getItems
() => SplitterItem[]

Returns the items of the splitter.

getPanels
() => PanelData[]

Returns the panels of the splitter.

getPanelById
(id: PanelId) => PanelData

Returns the panel with the specified id.

getPanelSize
(id: PanelId) => number

Returns the size of the specified panel.

isPanelCollapsed
(id: PanelId) => boolean

Returns whether the specified panel is collapsed.

isPanelExpanded
(id: PanelId) => boolean

Returns whether the specified panel is expanded.

collapsePanel
(id: PanelId) => void

Collapses the specified panel.

expandPanel
(id: PanelId, minSize?: number) => void

Expands the specified panel.

resizePanel
(id: PanelId, size: PanelSize) => void

Resizes the specified panel. Takes a percentage, or a size with a unit such as `"200px"`.

getLayout
() => string

Returns the layout of the splitter.

resetSizes
VoidFunction

Resets the splitter to its initial state.

getResizeTriggerState
(props: ResizeTriggerProps) => ResizeTriggerState

Returns the state of the resize trigger.

getRootState
() => RootState

Returns the state of the root. The panels share it.

Accessibility

Complies with the Window Splitter WAI-ARIA design pattern.