Splitter
A component that divides your interface into resizable sections
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.
| Attribute | Default | Type |
|---|---|---|
panels | PanelData[]The size constraints of the panels. | |
asChild | booleanUse 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 | booleanWhether resizing is disabled for the whole splitter | |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the splitter. Useful for composition. | |
keyboardResizeBy | 1 | numberThe percentage to resize the panel by when an arrow key is pressed. |
nonce | stringThe nonce for the injected splitter cursor stylesheet. | |
onCollapse | (details: ExpandCollapseDetails) => voidFunction called when a panel is collapsed. | |
onExpand | (details: ExpandCollapseDetails) => voidFunction called when a panel is expanded. | |
onResize | (details: ResizeDetails) => voidFunction called when the splitter is resized. | |
onResizeEnd | (details: ResizeEndDetails) => voidFunction called when the splitter resize ends. | |
onResizeStart | () => voidFunction called when the splitter resize starts. | |
orientation | 'horizontal' | 'horizontal' | 'vertical'The orientation of the splitter. Can be `horizontal` or `vertical` |
registry | SplitterRegistryThe 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 |
| Attribute | Description |
|---|---|
[data-splitter-root] | <uid> |
[data-orientation] | The orientation of the splitter |
[data-dragging] | Present when in the dragging state |
Panel
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
id | string | |
asChild | booleanUse 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. |
| Attribute | Description |
|---|---|
[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
| Prop | Default | Type |
|---|---|---|
hitAreaMargins | HitAreaMarginsThe hit area margins for resize handles. Larger margins make it easier to grab handles, especially on touch devices. | |
nonce | stringThe nonce for the injected cursor stylesheet (for CSP compliance). |
ResizeTriggerIndicator
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse 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.
| Attribute | Default | Type |
|---|---|---|
id | ResizeTriggerId | |
asChild | booleanUse 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. |
| Attribute | Description |
|---|---|
[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.
| Attribute | Default | Type |
|---|---|---|
value | UseSplitterReturn | |
asChild | booleanUse 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
| Property | Type |
|---|---|
dragging | booleanWhether 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[]) => voidSets the sizes of the panels. |
getItems | () => SplitterItem[]Returns the items of the splitter. |
getPanels | () => PanelData[]Returns the panels of the splitter. |
getPanelById | (id: PanelId) => PanelDataReturns the panel with the specified id. |
getPanelSize | (id: PanelId) => numberReturns the size of the specified panel. |
isPanelCollapsed | (id: PanelId) => booleanReturns whether the specified panel is collapsed. |
isPanelExpanded | (id: PanelId) => booleanReturns whether the specified panel is expanded. |
collapsePanel | (id: PanelId) => voidCollapses the specified panel. |
expandPanel | (id: PanelId, minSize?: number) => voidExpands the specified panel. |
resizePanel | (id: PanelId, size: PanelSize) => voidResizes the specified panel. Takes a percentage, or a size with a unit such as `"200px"`. |
getLayout | () => stringReturns the layout of the splitter. |
resetSizes | VoidFunctionResets the splitter to its initial state. |
getResizeTriggerState | (props: ResizeTriggerProps) => ResizeTriggerStateReturns the state of the resize trigger. |
getRootState | () => RootStateReturns the state of the root. The panels share it. |
Accessibility
Complies with the Window Splitter WAI-ARIA design pattern.