Skip to main content

Allotment API

Props​

NameTypeDefaultDescription
classNamestringSets a class name on the outer element.
defaultSizesnumber[]An array of initial sizes of the panes. If the sum of the sizes differs from the size of the container then the panes' sizes will be scaled proportionally.
idstringThe id to set on the outer element.
maxSizenumberInfinityMaximum size of any pane.
minSizenumber30Minimum size of any pane.
proportionalLayoutbooleantrueResize each view proportionally when resizing container.
separatorbooleantrueWhether to render a separator between panes.
sizesnumber[]Deprecated. Use defaultSizes instead.
snapbooleanfalseEnable snap to zero for all panes.
verticalbooleanfalseDirection to split. If true then the panes will be stacked vertically, otherwise they will be stacked horizontally.
onChange(sizes: number[]) => voidCallback that is fired when the pane sizes change (usually on drag). Recommended to add a debounce function to rate limit the callback.
onDragStart(sizes: number[]) => voidCallback that is fired when the user starts dragging a sash.
onDragEnd(sizes: number[]) => voidCallback that is fired when the user stops dragging a sash.
onReset() => voidCallback that is fired whenever the user double clicks a sash.
onVisibleChange(index: number, visible: boolean) => voidCallback that is fired whenever the user changes the visibility of a pane by snapping. Only called for panes with a visible prop, and only if the new value is different from it.

Ref methods​

You can use a ref to get access to the Allotment component instance and call its methods manually.

NameTypeDescription
reset() => voidDistribute the panes equally, then resize any pane with a preferredSize to that size. If an onReset prop is provided, it is called instead.
resize(sizes: number[]) => voidResize the panes to the given sizes.
import * as React from "react";
import { Allotment, AllotmentHandle } from "allotment";

function App() {
const ref = React.useRef<AllotmentHandle>(null);

return (
<div>
<button onClick={() => ref.current?.reset()}>Reset</button>
<button onClick={() => ref.current?.resize([100, 200])}>Resize</button>
<Allotment ref={ref}>
<div />
<div />
</Allotment>
</div>
);
}