Splitter
A component that divides your interface into resizable sections
Anatomy
To set up the splitter correctly, you'll need to understand its anatomy and how we name its parts.
Each part includes a
data-partattribute to help identify them in the DOM.
Examples
Learn how to use the Splitter component in your project. Let's take a look at the most basic example:
Example not foundExample not foundExample not foundExample not foundUsing Render Props
The Splitter component allows you to pass a function as a child to gain direct access to its API. This provides more control and allows you to modify the size of the panels programmatically:
Example not foundExample not foundExample not foundExample not foundHandling Events
Splitter also provides onResizeStart, onResize, and onResizeEnd events which can be useful to perform some actions
during the start and end of the resizing process:
Example not foundExample not foundExample not foundExample not foundVertical Splitter
By default, the Splitter component is horizontal. If you need a vertical splitter, use the orientation prop:
Example not foundExample not foundExample not foundExample not foundCollapsible Panels
To make a panel collapsible, set the collapsible prop to true on the panel you want to make collapsible.
Additionally, you can use the collapsedSize prop to set the size of the panel when it's collapsed.
This can be useful for building sidebar layouts.
Example not foundExample not foundExample not foundExample not foundMultiple Panels
Here's an example of how to use the Splitter component with multiple panels.
Example not foundExample not foundExample not foundExample not foundUsing the Root Provider
The RootProvider component provides a context for the splitter. It accepts the value of the useSplitter hook. You
can leverage it to access the component state and methods from outside the splitter.
Example not foundExample not foundExample not foundExample not foundIf you're using the
RootProvidercomponent, you don't need to use theRootcomponent.
API Reference
Props
Root
| Prop | 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. For more details, read our Composition guide. | |
defaultSize | number[]The initial size of the panels when rendered. Use when you don't need to control the size of the panels. | |
id | stringThe unique identifier of the machine. | |
ids | Partial<{
root: string
resizeTrigger: (id: string) => string
label: (id: string) => string
panel: (id: string | number) => string
}>The ids of the elements in the splitter. Useful for composition. | |
keyboardResizeBy | numberThe number of pixels to resize the panel by when the keyboard is used. | |
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` |
size | number[]The controlled size data of the panels |
| Data Attribute | Value |
|---|---|
[data-scope] | splitter |
[data-part] | root |
[data-orientation] | The orientation of the splitter |
Panel
| Prop | Default | Type |
|---|---|---|
id | string | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
| Data Attribute | Value |
|---|---|
[data-scope] | splitter |
[data-part] | panel |
[data-orientation] | The orientation of the panel |
[data-id] | |
[data-index] | The index of the item |
ResizeTrigger
| Prop | Default | Type |
|---|---|---|
id | `${string}:${string}` | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
disabled | boolean |
| Data Attribute | Value |
|---|---|
[data-scope] | splitter |
[data-part] | resize-trigger |
[data-id] | |
[data-orientation] | The orientation of the resizetrigger |
[data-focus] | Present when focused |
[data-disabled] | Present when disabled |
RootProvider
| Prop | Default | Type |
|---|---|---|
value | UseSplitterReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
Context
These are the properties available when using Splitter.Context, useSplitterContext hook or useSplitter hook.
API
| Property | Type |
|---|---|
dragging | booleanWhether the splitter is currently being resized. |
getSizes | () => number[]Returns the current sizes of the panels. |
setSizes | (size: number[]) => voidSets the sizes of the panels. |
getItems | () => SplitterItem[]Returns the items of the splitter. |
getPanelSize | (id: string) => numberReturns the size of the specified panel. |
isPanelCollapsed | (id: string) => booleanReturns whether the specified panel is collapsed. |
isPanelExpanded | (id: string) => booleanReturns whether the specified panel is expanded. |
collapsePanel | (id: string) => voidCollapses the specified panel. |
expandPanel | (id: string, minSize?: number) => voidExpands the specified panel. |
resizePanel | (id: string, unsafePanelSize: number) => voidResizes the specified panel. |
getLayout | () => stringReturns the layout of the splitter. |
resetSizes | VoidFunctionResets the splitter to its initial state. |
Accessibility
Complies with the Window Splitter WAI-ARIA design pattern.