react-resizable-panels: React components for resizable panel groups/layouts.
If you like this project there are several ways to support it:
Begin by installing the library from NPM:
npm install react-resizable-panelsTypeScript definitions are included within the published dist folder
Frequently asked questions can be found here.
Documentation for this project is available at react-resizable-panels.vercel.app.
A Group wraps a set of resizable Panel components. Group content can be resized horizontally or vertically.
Group elements always include the following attributes:
<div data-group data-testid="group-id-prop" id="group-id-prop">ℹ️ Test id can be used to narrow selection when unit testing.
None
| Name | Description |
|---|---|
| className | CSS class name. |
| id | Uniquely identifies this group within an application.
Falls back to ℹ️ This value will also be assigned to the |
| style | CSS properties.
|
| children | Panel and Separator components that comprise this group. |
| defaultLayout | Default layout for the Group. ℹ️ This value allows layouts to be remembered between page reloads. |
| disableCursor | This library sets custom mouse cursor styles to indicate drag state. Use this prop to disable that behavior for Panels and Separators in this group. |
| disabled | Disable resize functionality. |
| elementRef | Ref attached to the root |
| groupRef | Exposes the following imperative API:
ℹ️ The |
| onLayoutChange | Called when the Group's layout is changing.
|
| onLayoutChanged | Called after the Group's layout has been changed. ℹ️ For layout changes caused by pointer events, this method is not called until the pointer has been released. This method is recommended when saving layouts to some storage api. ℹ️ The second argument contains meta information about the layout change.
The |
| resizePreviewMode | Controls whether pointer dragging updates Defaults to Customize previews using the |
| resizeTargetMinimumSize | Minimum size of the resizable hit target area (either
ℹ️ Apple interface guidelines suggest |
| orientation | Specifies the resizable orientation ("horizontal" or "vertical"); defaults to "horizontal" |
A Panel wraps resizable content and can be configured with min/max size constraints and collapsible behavior.
Panel size props can be in the following formats:
- Percentage of the parent Group (0..100)
- Pixels
- Relative font units (em, rem)
- Viewport relative units (vh, vw)
ℹ️ Numeric values are assumed to be pixels. Strings without explicit units are assumed to be percentages (0%..100%). Percentages may also be specified as strings ending with "%" (e.g. "33%") Pixels may also be specified as strings ending with the unit "px". Other units should be specified as strings ending with their CSS property units (e.g. 1rem, 50vh)
Panel elements always include the following attributes:
<div data-panel data-testid="panel-id-prop" id="panel-id-prop">ℹ️ Test id can be used to narrow selection when unit testing.
None
| Name | Description |
|---|---|
| className | CSS class name.
|
| id | Uniquely identifies this panel within the parent group.
Falls back to ℹ️ This prop is used to associate persisted group layouts with the original panel. ℹ️ This value will also be assigned to the |
| style | CSS properties.
|
| collapsedSize | Panel size when collapsed; defaults to 0%. |
| collapsedThreshold | Distance a collapsible panel must be resized past its For example if a panel declares ℹ️ Interpretation rules:
|
| collapsible | This panel can be collapsed. ℹ️ A collapsible panel will collapse when it's size is less than of the specified |
| defaultSize | Default size of Panel within its parent group; default is auto-assigned based on the total number of Panels. ℹ️ Interpretation rules:
|
| disabled | When disabled, a panel cannot be resized either directly or indirectly (by resizing another panel). |
| elementRef | Ref attached to the root |
| groupResizeBehavior | How should this Panel behave if the parent Group is resized?
Defaults to
ℹ️ Panel min/max size constraints may impact this behavior.
|
| maxSize | Maximum size of Panel within its parent group; defaults to ℹ️ Interpretation rules:
|
| minSize | Minimum size of Panel within its parent group; defaults to 0%. ℹ️ Interpretation rules:
|
| onResize | Called when panel sizes change. @param panelSize Panel size (both as a percentage of the parent Group and in pixels) @param id Panel id (if one was provided as a prop) @param prevPanelSize Previous panel size (will be undefined on mount) |
| panelRef | Exposes the following imperative API:
ℹ️ The |
Separators are not required but they are recommended as they improve keyboard accessibility.
Separator elements always include the following attributes:
<div data-separator data-testid="separator-id-prop" id="separator-id-prop" role="separator">ℹ️ Test id can be used to narrow selection when unit testing.
ℹ️ In addition to the attributes shown above, separator also renders all required WAI-ARIA properties.
None
| Name | Description |
|---|---|
| className | CSS class name. ℹ️ Use the
|
| id | Uniquely identifies the separator within the parent group.
Falls back to ℹ️ This value will also be assigned to the |
| style | CSS properties. ℹ️ Use the
|
| disabled | When disabled, the separator cannot be used to resize its neighboring panels. ℹ️ The panels may still be resized indirectly (while other panels are being resized). To prevent a panel from being resized at all, it needs to also be disabled. |
| disableDoubleClick | When true, double-clicking this |
| elementRef | Ref attached to the root |
| preview | Overrides the |
A Grid arranges resizable Cells in two dimensions. Columns can be resized horizontally and rows can be resized vertically; dragging the point where a column boundary and a row boundary intersect resizes both.
Size constraints (e.g. min/max size, collapsible) are specified per track (column or row), using the same format as Panel props.
Cells can span multiple columns and/or rows. Track boundaries cannot be resized alongside of a cell that spans across them.
Grid elements always include the following attributes:
<div data-grid data-testid="grid-id-prop" id="grid-id-prop">ℹ️ Test id can be used to narrow selection when unit testing.
| Name | Description |
|---|---|
| columns | Grid columns; either the number of columns or an array of size constraints (one per column). |
| rows | Grid rows; either the number of rows or an array of size constraints (one per row). |
| Name | Description |
|---|---|
| className | CSS class name. |
| id | Uniquely identifies this grid within an application.
Falls back to ℹ️ This value will also be assigned to the |
| style | CSS properties. |
| children | Cell and Gridline components that comprise this grid. |
| defaultLayout | Default layout for either or both of the Grid's axes. ℹ️ This value allows layouts to be remembered between page reloads. |
| disableCursor | This library sets custom mouse cursor styles to indicate drag state. Use this prop to disable that behavior for this grid. |
| disabled | Disable resize functionality. |
| elementRef | Ref attached to the root |
| gridRef | Exposes the following imperative API:
ℹ️ The |
| onLayoutChange | Called when the Grid's layout is changing.
|
| onLayoutChanged | Called after the Grid's layout has been changed. ℹ️ For layout changes caused by pointer events, this method is not called until the pointer has been released. This method is recommended when saving layouts to some storage api. |
| resizeTargetMinimumSize | Minimum size of the resizable hit target area (either a ℹ️ Refer to the |
A Cell occupies one or more tracks (columns and rows) within a Grid. Cells are resized along with the tracks they occupy.
Cell elements always include the following attributes:
<div data-cell data-testid="cell-id-prop" id="cell-id-prop">ℹ️ Test id can be used to narrow selection when unit testing.
| Name | Description |
|---|---|
| column | Index of the (first) column this cell occupies. |
| row | Index of the (first) row this cell occupies. |
| Name | Description |
|---|---|
| className | CSS class name. |
| id | Uniquely identifies this cell within the parent grid.
Falls back to ℹ️ This value will also be assigned to the |
| style | CSS properties. |
| children | Cell contents. |
| columnSpan | Number of columns this cell spans; defaults to 1. |
| elementRef | Ref attached to the root |
| rowSpan | Number of rows this cell spans; defaults to 1. |
Resizes the columns (or rows) of a Grid.
For example:
// Rendered between columns 0 and 1 and spans all rows
<Gridline type="column" column={1} />// Rendered between rows 0 and 1 and spans all columns
<Gridline type="row" row={1} />// Rendered between columns 0 and 1 alongside of row 2 only
<Gridline type="column" column={1} row={2} rowSpan={1} />A gridline should not be rendered alongside of a Cell that spans across its boundary (this includes disabled gridlines; an error will be logged to the console); render multiple gridlines along the same boundary instead (e.g. before and after the spanning Cell).
ℹ️ Once a boundary contains a gridline, it can only be resized using gridlines; the parts of the boundary that aren't alongside of a gridline can't be dragged.
Where column and row gridlines intersect, dragging resizes both axes.
Gridlines are not required but they are recommended as they improve keyboard accessibility.
Gridline elements always include the following attributes:
<div aria-orientation="vertical" data-separator role="separator">ℹ️ Column gridlines are vertical (aria-orientation="vertical") and row gridlines are horizontal (aria-orientation="horizontal").
ℹ️ In addition to the attributes shown above, gridlines also render all required WAI-ARIA properties.
ℹ️ Gridlines rendered by another component (rather than directly within the Grid) aren't detected until they mount, so server-rendered layouts may shift slightly during hydration.
| Name | Description |
|---|---|
| type | Column gridlines are vertical; they resize the columns on either side of them. Row gridlines are horizontal; they resize the rows on either side of them. |
| Name | Description |
|---|---|
| children | Gridline contents (e.g. a drag handle icon). |
| className | CSS class name. ℹ️ Use the |
| disabled | When disabled, the gridline cannot be used to resize its neighboring tracks. ℹ️ The tracks may still be resized indirectly (e.g. by an intersecting gridline or another boundary). To prevent a track from being resized at all, it needs to also be disabled. |
| elementRef | Ref attached to the root |
| style | CSS properties. |
| column | When |
| row | When |
| rowSpan | Number of rows a column gridline spans; defaults to all rows (starting from ℹ️ Gridlines can span a subset of rows in order to avoid cells that span across the boundary they sit on; multiple gridlines can be rendered along the same boundary (e.g. above and below a spanning cell). |
| columnSpan | Number of columns a row gridline spans; defaults to all columns (starting from ℹ️ Gridlines can span a subset of columns in order to avoid cells that span across the boundary they sit on; multiple gridlines can be rendered along the same boundary (e.g. before and after a spanning cell). |
