- Dependencies
- Installation and configuration
- Adding CSS Reference
- Adding Splitter to the project
- Orientation
- Load content to the pane
- See Also
Contact Support
Getting Started
8 May 202515 minutes to read
The following section explains the steps required to build the Splitter component with step-by-step procedure.
Dependencies
The following list of dependencies required to use the Splitter component in your application:
|-- @syncfusion/ej2-layouts
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-react-layouts
|-- @syncfusion/ej2-react-base
Installation and configuration
To easily set up a React application, use create-vite-app
, which provides a faster development environment, smaller bundle sizes, and optimized builds compared to traditional tools like create-react-app
. For detailed steps, refer to the Vite installation instructions. Vite sets up your environment using JavaScript and optimizes your application for production.
Note: To create a React application using
create-react-app
, refer to this documentation for more details.
To create a new React application, run the following command.
npm create vite@latest my-app
To set-up a React application in TypeScript environment, run the following command.
npm create vite@latest my-app -- --template react-ts
cd my-app
npm run dev
To set-up a React application in JavaScript environment, run the following command.
npm create vite@latest my-app -- --template react
cd my-app
npm run dev
Install the below required dependency package in order to use the Splitter
component in your application.
npm install @syncfusion/ej2-react-layouts --save
Adding CSS Reference
The Splitter CSS files are available in the ej2-layouts
package folder.
This can be referred in your application using the following code.
[src/App.css]
@import '../../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-layouts/styles/material.css';
Adding Splitter to the project
The Splitter can be initialized through <SplitterComponent>
tag-directive with <PanesDirective>
and <PaneDirective>
as child elements respectively.
Please refer the below code snippet,
import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from "react";
class App extends React.Component {
public render() {
return (
<div className="App">
<SplitterComponent id="splitter" height="250px" width="600px">
<PanesDirective>
<PaneDirective/>
<PaneDirective/>
<PaneDirective/>
</PanesDirective>
</SplitterComponent>
</div>
);
}
}
export default App;
Now run the npm run dev
command in the console to start the development server. This command compiles your code and serves the application locally, opening it in the browser.
npm run dev
Output will be as follows:
import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from "react";
class App extends React.Component {
render() {
return (<div className="App">
<SplitterComponent id="splitter" height="250px" width="600px">
<PanesDirective>
<PaneDirective />
<PaneDirective />
<PaneDirective />
</PanesDirective>
</SplitterComponent>
</div>);
}
}
export default App;
import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from "react";
class App extends React.Component {
public render() {
return (
<div className="App">
<SplitterComponent id="splitter" height="250px" width="600px">
<PanesDirective>
<PaneDirective/>
<PaneDirective/>
<PaneDirective/>
</PanesDirective>
</SplitterComponent>
</div>
);
}
}
export default App;
Orientation
Splitter supports both Horizontal
and Vertical
orientation for the panes. By default, it will be rendered in Horizontal
orientation. You can change it by using orientation property.
import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from "react";
class App extends React.Component {
render() {
return (<div className="App">
<SplitterComponent id="splitter-vertical" height="250px" width="50%" orientation={'Vertical'}>
<PanesDirective>
<PaneDirective />
<PaneDirective />
</PanesDirective>
</SplitterComponent>
</div>);
}
}
export default App;
import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from "react";
class App extends React.Component {
public render() {
return (<div className="App">
<SplitterComponent id="splitter-vertical" height="250px" width="50%" orientation = {'Vertical'}>
<PanesDirective>
<PaneDirective/>
<PaneDirective/>
</PanesDirective>
</SplitterComponent>
</div>
);
}
}
export default App;
Load content to the pane
You can load the pane contents in either HTML element or string types using content property.
For detailed information, refer to the Pane Content section
import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from "react";
class App extends React.Component {
firstPane() {
return (<div>
<div className="content">
<h3 className="h3">HTML</h3>
<div className="code-preview">
<<span>!DOCTYPE html></span>
<div><<span>html></span></div>
<div><<span>body></span></div>
<<span>div</span> id="custom-image">
<div><<span>img</span> src="src/albert.png"></div>
<div><<span>div</span>></div>
<div><<span>/body></span></div>
<div><<span>/html></span></div>
</div>
</div>
</div>);
}
secondPane() {
const openBrace = '{';
const closeBrace = '}';
return (<div>
<div className="content">
<h3 className="h3">CSS</h3>
<div className="code-preview">
<span>img {openBrace} </span>
<div id="code-text">margin:<span>0 auto;</span></div>
<div id="code-text">display:<span>flex;</span></div>
<div id="code-text">height:<span>70px;</span></div>
<span>{closeBrace}</span>
</div>
</div>
</div>);
}
thirdPane() {
const openBrace = '{';
const closeBrace = '}';
return (<div>
<div className="content">
<h3 className="h3">JavaScript</h3>
<div className="code-preview">
<span>var</span> image = document.getElementById("custom-image");
<div>image.addEventListener("click", function() {openBrace}</div>
<div> // Code block for click action</div>
// Code block for click action</div>
<span> {closeBrace}) </span>
</div>
</div>
</div>);
}
render() {
return (<div className="App">
<SplitterComponent id="splitter" height="250px" width="550px">
<PanesDirective>
<PaneDirective content={this.firstPane}/>
<PaneDirective content={this.secondPane}/>
<PaneDirective content={this.thirdPane}/>
</PanesDirective>
</SplitterComponent>
</div>);
}
}
export default App;
import { PaneDirective, PanesDirective, SplitterComponent } from '@syncfusion/ej2-react-layouts';
import * as React from "react";
class App extends React.Component {
public firstPane() {
return (
<div>
<div className="content">
<h3 className="h3">HTML</h3>
<div className="code-preview">
<<span>!DOCTYPE html></span>
<div><<span>html></span></div>
<div><<span>body></span></div>
<<span>div</span> id="custom-image">
<div><<span>img</span> src="src/albert.png"></div>
<div><<span>div</span>></div>
<div><<span>/body></span></div>
<div><<span>/html></span></div>
</div>
</div>
</div>
);
}
public secondPane() {
const openBrace: string = '{';
const closeBrace: string = '}';
return (
<div>
<div className="content">
<h3 className="h3">CSS</h3>
<div className="code-preview">
<span>img {openBrace} </span>
<div id="code-text">margin:<span>0 auto;</span></div>
<div id="code-text">display:<span>flex;</span></div>
<div id="code-text">height:<span>70px;</span></div>
<span>{closeBrace}</span>
</div>
</div>
</div>
);
}
public thirdPane() {
const openBrace: string = '{';
const closeBrace: string = '}';
return (
<div>
<div className="content">
<h3 className="h3">JavaScript</h3>
<div className="code-preview">
<span>var</span> image = document.getElementById("custom-image");
<div>image.addEventListener("click", function() { openBrace }</div>
<div>// Code block for click action</div>
<span> {closeBrace }) </span>
</div>
</div>
</div>
);
}
public render() {
return (<div className="App">
<SplitterComponent id="splitter" height="250px" width="550px">
<PanesDirective>
<PaneDirective content = {this.firstPane}/>
<PaneDirective content = {this.secondPane}/>
<PaneDirective content = {this.thirdPane}/>
</PanesDirective>
</SplitterComponent>
</div>);
}
}
export default App;