React Split Pane
Split-Pane component built with React, can be split vertically or horizontally.
Check out the demos
By dragging 'draggable' surface you can change size of the first pane.
The first pane keeps then its size while the second pane is resized by browser window.
By default it is the left pane for 'vertical' SplitPane and the top pane for 'horizontal' SplitPane.
If you want to keep size of the second pane and let the first pane to shrink or grow by browser window dimensions,
set SplitPane prop
second. In case of 'horizontal' SplitPane the height of bottom pane remains the same.
Resizing can be disabled by passing the
enableResizing prop as
false. Resizing is enabled by default.
You can also set the size of the pane using the
size prop. Note that a size set through props ignores the
In this example right pane keeps its width 200px while user is resizing browser window.
You can limit the maximal size of the 'fixed' pane using the maxSize parameter with a positive value (measured in pixels but state just a number). If you wrap the SplitPane into a container component (yes you can, just remember the container has to have the relative or absolute positioning), then you'll need to limit the movement of the splitter (resizer) at the end of the SplitPane (otherwise it can be dragged outside the SplitPane and you don't catch it never more). For this purpose use the maxSize parameter with value 0. When dragged the splitter/resizer will stop at the border of the SplitPane component and think this you'll be able to pick it again and drag it back then. And more: if you set the maxSize to negative value (e.g. -200), then the splitter stops 200px before the border (in other words it sets the minimal size of the 'resizable' pane in this case). This can be useful also in the full-screen case of use.
Each SplitPane accepts an onChange function prop. Used in conjunction with defaultSize and a persistence layer, you can ensure that your splitter choices survive a refresh of your app.
For example, if you are comfortable with the trade-offs of localStorage, you could do something like the following:
localStorage.setItem('splitPos', size) }>
Disclaimer: localStorage has a variety of performance trade-offs. Browsers such as Firefox have now optimized localStorage use so that they will asynchronously initiate a read of all saved localStorage data for an origin once they know the page will load. If the data has not fully loaded by the time code accesses localStorage, the code will cause the page's main thread to block until the database load completes. When the main thread is blocked, no other JS code will run or layout will occur. In multiprocess browsers and for users with fast disk storage, this will be less of a problem. You are likely to get yelled at if you use localStorage.
A potentially better idea is to use something like https://github.com/mozilla/localForage although hooking it up will be slightly more involved. You are likely to be admired by all for judiciously avoiding use of localStorage.
If you need more control over resizing, SplitPane can notify you about when resizing started
and when it ended through two callbacks:
This gives a single pixel wide divider, but with a 'grabbable' surface of 11 pixels.
background-clip: padding-box; for making transparent borders possible.
You can also pass inline styles to the components via props. These are:
paneStyle- Styling to be applied to both panes
pane1Style- Styling to be applied to the first pane, with precedence over
pane2Style- Styling to be applied to the second pane, with precedence over
resizerStyle- Styling to be applied to the resizer bar
I'm always happy to receive Pull Requests for contributions of any kind.
If possible / necessary then please try and include a test and/or update the examples.