Introducing Syncfusion’s React Splitter Component | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
React Splitter component

Introducing Syncfusion’s React Splitter Component

We are happy to introduce the final version of the React Splitter component. The preview version of the React Splitter component was introduced with the 2018 Volume 4 release. Now, the official version of the Splitter has been improved with collapsible panes to enhance its use case in our 2019 Volume 1 release.

The React Splitter component is a layout component that supports all important features such as resizing, collapsing, and nesting panes. It is designed using a CSS3 flexbox to bring a properly structured layout to its panes. The component simplifies design layouts when an application has different and complex layouts.

In this blog post, we will summarize key features of the React Splitter component:

  • Panes with different orientations.
  • Resizable panes.
  • Collapsible panes.
  • Nesting panes.
  • Integration with other React UI components.

Panes with different orientations

The Splitter component’s panes flow either from left to right or top to bottom. The Splitter renders its panes horizontally with default settings, but you can change its orientation to vertical using the ‘orientation’ property.

The following code example explains how to render a horizontal or vertical splitter.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
import './App.css';

class Splitter extends React.Component {

public LeftPane(): JSX.Element {
return (
<div className='splitter-content'> <span > Left pane </span> </div>
)
}

public RightPane(): JSX.Element {
return (
<div className='splitter-content'> <span > Right pane </span> </div>
)
}

public TopPane(): JSX.Element {
return (
<div className='splitter-content'> <span > Top pane </span> </div>
)
}

public BottomPane(): JSX.Element {
return (
<div className='splitter-content'> <span > Bottom pane </span> </div>
)
}

public render() {
return (
<div className="App">

{/* Horizontal Splitter */}
<SplitterComponent id="horizontalSplitter" height="100px" width="50%" separatorSize={4}>
<PanesDirective>
<PaneDirective size="50%" min="60px" content={this.LeftPane} />
<PaneDirective content={this.RightPane} />
</PanesDirective>
</SplitterComponent>

{/* Vertical Splitter */}
<SplitterComponent id="verticalSplitter" height="200px" width="50%" separatorSize={4}
orientation="Vertical">
<PanesDirective>
<PaneDirective size='50%' min='60px' content={this.TopPane} />
<PaneDirective content={this.BottomPane} />
</PanesDirective>
</SplitterComponent>

</div>

);
}
}

export default Splitter;
Horizontal and vertical splitters
Horizontal and vertical splitters

Resizable panes

You can adjust a pane’s width or height dynamically by resizing it horizontally or vertically using the resize gripper. The resize gripper is available in the middle of all the panes. If you want to disable the resize action for specific panes, use the pane settings.

The following code snippet shows how we can control resizing behavior in specific panes.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
import './App.css';

class ResizePanes extends React.Component {

public Pane1(): JSX.Element {
return (
<div className='splitter-content'> <span> Pane 1 </span> </div>
)
}

public Pane2(): JSX.Element {
return (
<div className='splitter-content'> <span> Pane 2 </span> </div>
)
}

public Pane3(): JSX.Element {
return (
<div className='splitter-content'> <span> Pane 3 </span> </div>
)
}

public render() {
return (
<div className="App">
{/* Resizable Panes */}
<SplitterComponent id="ResizableSplitter" height="100px" width="50%" separatorSize={4}>
<PanesDirective>
<PaneDirective content={this.Pane1} />
<PaneDirective content={this.Pane2} />
<PaneDirective content={this.Pane3} resizable={false} />
</PanesDirective>
</SplitterComponent>
</div>
);
}
}

export default ResizePanes;
Resizable split panes
Panes with hided resizing bar

Collapsible panes

In the preview version of Splitter, you could only resize panes. Now, the Splitter is enhanced with collapsible support for them. You can dynamically expand or collapse the panes by interacting with related icons. A pane’s width or height automatically adjusts to accommodate the remaining space. In addition, there is an option to collapse the pane on component initialization itself.

The expand and collapse functionality of the Splitter component is explained in the following code block.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
import './App.css';

class CollapsibleSplitter extends React.Component {

public Pane1(): JSX.Element {
return (
<div className='splitter-content'> <span> This pane has expand/collapse functionality </span> </div>
)
}

public Pane2(): JSX.Element {
return (
<div className='splitter-content'> <span> This pane with collapse state on init </span> </div>
)
}

public Pane3(): JSX.Element {
return (
<div className='splitter-content'> <span> This pane has not collapsible feature </span> </div>
)
}

public render() {
return (
<div className="App">
{/* Expand and Collapse Panes */}
<SplitterComponent id="CollapsibleSplitter" height="100px" width="70%" separatorSize={4}>
<PanesDirective>
<PaneDirective content={this.Pane1} collapsible={true} />
<PaneDirective content={this.Pane2} collapsible={true} collapsed={true} />
<PaneDirective content={this.Pane3} />
</PanesDirective>
</SplitterComponent>
</div>
);
}
}

export default CollapsibleSplitter;
Collapsible splitter
The Splitter with expand and collapse actions

Nesting panes

You can nest a Splitter component within the panes of another Splitter component to create a complex layout. To create nested panes, render the Splitter as shown in the following code example.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
import './App.css';

class NestedSplitter extends React.Component {

public NestPanes = () => {
return (<SplitterComponent id="NestedSplitter">
<PanesDirective>
<PaneDirective content={this.LeftPane} />
<PaneDirective content={this.MiddlePane} />
<PaneDirective content={this.RightPane} />
</PanesDirective>
</SplitterComponent>
)
}

public LeftPane(): JSX.Element {
return (
<div className='splitter-content'> <span> Left pane </span> </div>
)
}

public MiddlePane(): JSX.Element {
return (
<div className='splitter-content'> <span> Middle pane </span> </div>
)
}

public RightPane(): JSX.Element {
return (
<div className='splitter-content'> <span> Right pane </span> </div>
)
}

public BottomPane(): JSX.Element {
return (
<div className='splitter-content'> <span> Bottom pane </span> </div>
)
}

public render() {
return (
<div className="App">
{/* Nested Splitter */}
<SplitterComponent id="MainSplitter" orientation="Vertical" height="200px" width="70%" separatorSize={4}>
<PanesDirective>
<PaneDirective content={this.NestPanes} />
<PaneDirective content={this.BottomPane} />
</PanesDirective>
</SplitterComponent>

</div>
);
}
}

export default NestedSplitter;
React nested splitter
The Splitter with nesting panes

 

Integrate other React UI components

Since the React Splitter is a layout container, you can load different types of content within panes, whether it be plain text, HTML content, or another React UI component.

The following code example demonstrates how to integrate other React UI components within the panes of a splitter.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import { AccordionComponent, AccordionItemDirective, AccordionItemsDirective } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import './App.css';

export class AccordionIntegration extends React.Component {

public RightPane(): JSX.Element {
return (
<div className='splitter-content'> <span> Right pane to display the details. </span> </div>
)
}

public AccordionRender() {
return (
<div className='splitter-content'><span>Left pane with React UI Accordion component. </span>
<div>
<AccordionComponent>
<AccordionItemsDirective>
<AccordionItemDirective header="ASP.NET MVC" content="Content of pane 1" />
<AccordionItemDirective header="ASP.NET Core" content="Content of pane 2" />
<AccordionItemDirective header="JavaScript" content="Content of pane 3" />
</AccordionItemsDirective>
</AccordionComponent>
</div>
</div>
);
}

public render() {
this.AccordionRender = this.AccordionRender.bind(this);
return (
<div className="App">
<SplitterComponent id="AccordionUI" height="200px" width="70%" separatorSize={4}>
<PanesDirective>
<PaneDirective content={this.AccordionRender} />
<PaneDirective content={this.RightPane} />
</PanesDirective>
</SplitterComponent>
</div>
);
}
}

export default AccordionIntegration;
React UI Accordion within a split pane
Integrated React UI Accordion within a pane

Note: Refer to our documentation page for more details on the React UI Accordion component and its properties.

Creating a layout for a use case example

Use the Splitter component to construct different layouts with flexible options such as an Outlook-style layout, code editor layout, or Windows Explorer-style layout. Now, let’s see how the React Splitter helps to render a code editor UI layout with the following code examples.

Step 1: Declare the panes with content.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
import './App.css';

class App extends React.Component {

public LeftPane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>HTML</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;div id='custom-image'&gt; &lt;img src='src/albert.png'&gt; &lt;div&gt; &lt;/body&gt; &lt;/html&gt;" }} />
</div>
)
}

public MiddlePane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>CSS</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "img { margin:0 auto; display:flex; height:70px; }" }} />
</div>
)
}

public RightPane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>JavaScript</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "var image = document.getElementById('custom-image');<br/>image.addEventListener('click', function()<br/> { }" }} /> </div>
)
}

public BottomPane(): JSX.Element {
return (
<div className='splitter-content'><strong>Preview of Sample</strong>
<div className="splitter-image">
<img className="img1" src="https://ej2.syncfusion.com/demos/src/listview/images/albert.png" />
</div>
</div>
)
}


}
export default App;

Step 2: Create the child (inner) splitter as shown in the following code example.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
import './App.css';

class App extends React.Component {

public LeftPane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>HTML</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;div id='custom-image'&gt; &lt;img src='src/albert.png'&gt; &lt;div&gt; &lt;/body&gt; &lt;/html&gt;" }} />
</div>
)
}

public MiddlePane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>CSS</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "img { margin:0 auto; display:flex; height:70px; }" }} />
</div>
)
}

public RightPane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>JavaScript</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "var image = document.getElementById('custom-image');<br/>image.addEventListener('click', function()<br/> { }" }} /> </div>
)
}

public BottomPane(): JSX.Element {
return (
<div className='splitter-content'><strong>Preview of Sample</strong>
<div className="splitter-image">
<img className="img1" src="https://ej2.syncfusion.com/demos/src/listview/images/albert.png" />
</div>
</div>
)
}

public NestPanes = () => {
return (<SplitterComponent id="NestedSplitter">
<PanesDirective>
<PaneDirective content={this.LeftPane} />
<PaneDirective content={this.MiddlePane} />
<PaneDirective content={this.RightPane} />
</PanesDirective>
</SplitterComponent>
)
}
}
export default App;

Step 3: Render the parent (main) splitter with following code example.

import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
import './App.css';

class App extends React.Component {

public LeftPane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>HTML</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;div id='custom-image'&gt; &lt;img src='src/albert.png'&gt; &lt;div&gt; &lt;/body&gt; &lt;/html&gt;" }} />
</div>
)
}

public MiddlePane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>CSS</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "img { margin:0 auto; display:flex; height:70px; }" }} />
</div>
)
}

public RightPane(): JSX.Element {
return (
<div className='splitter-content'>
<span><strong>JavaScript</strong> </span>
<p dangerouslySetInnerHTML={{ __html: "var image = document.getElementById('custom-image');<br/>image.addEventListener('click', function()<br/> { }" }} /> </div>
)
}

public BottomPane(): JSX.Element {
return (
<div className='splitter-content'><strong>Preview of Sample</strong>
<div className="splitter-image">
<img className="img1" src="https://ej2.syncfusion.com/demos/src/listview/images/albert.png" />
</div>
</div>
)
}

public NestPanes = () => {
return (<SplitterComponent id="NestedSplitter">
<PanesDirective>
<PaneDirective content={this.LeftPane} />
<PaneDirective content={this.MiddlePane} />
<PaneDirective content={this.RightPane} />
</PanesDirective>
</SplitterComponent>
)
}

public render() {
return (
<div className="App">
{/* Code Editor UI */}
<SplitterComponent id="MainSplitter" orientation="Vertical" height="300px" width="80%" separatorSize={4}>
<PanesDirective>
<PaneDirective content={this.NestPanes} />
<PaneDirective content={this.BottomPane} />
</PanesDirective>
</SplitterComponent>

</div>
);
}
}
export default App;
Code editor UI layout using React Splitter
Code editor UI layout

Summary

I hope you find this React Splitter component helpful to design your layout-related applications with simple configurations. We look forward to you trying this component and providing your feedback through this feedback portal. You can also contact us through our support forum or Direct-Trac.

You can explore our online demo and our documentation to learn more. You can check out the source for our React Splitter on GitHub, too, at https://github.com/syncfusion/ej2-react-ui-components. The component is also available for JavaScript, Angular, Vue, ASP.NET Core, and ASP.NET MVC.

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed