Open and close the sidebar in EJ2 TypeScript Sidebar control

2 May 20235 minutes to read

Opening and closing the Sidebar can be achieved with built-in public methods.

  • show(): Method to open the Sidebar.
  • hide(): Method to close the Sidebar.
  • toggle(): Method to toggle between open and close states of the Sidebar.

In the following sample, toggle method has been used to show or hide the Sidebar on button click.

import { Sidebar } from '@syncfusion/ej2-navigations';
import { enableRipple } from '@syncfusion/ej2-base';

//Sidebar initialization
let defaultSidebar: Sidebar = new Sidebar({
    showBackdrop: false,
        console.log("Sidebar is opened");
    close: function(e)
       console.log("Sidebar is closed");
//end of Sidebar initialization

// Open the Sidebar
document.getElementById('open').onclick = (): void => {;

// Toggle(Open/Close) the Sidebar
document.getElementById('toggle').onclick = (): void => {

// Close the Sidebar
document.getElementById('close').onclick = (): void => {
<!DOCTYPE html>
<html lang="en">

    <title>Essential JS 2 Sidebar</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="styles.css" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>
<script src="" type ="text/javascript"></script>

    <div id='loader'>LOADING....</div>
    <div id='container'>
        <!-- sidebar element declaration-->
        <aside id="default">
            <div class="title"> Sidebar content</div>
            <div class="sub-title">
                Click the button to close the Sidebar.
            <div class="center-align">
                <button id="close" class="e-btn close-btn">Close Sidebar</button>
        <!-- end of sidebar element -->
        <!-- main content declaration -->
            <div class="title">Main content</div>
            <div class="sub-title"> Click the button to Open the Sidebar.</div>
            <div style="padding:20px" class="center-align">
                <button id="open" class="e-btn e-info">Open Sidebar</button>
            <div class="sub-title"> Click the button to open/close the Sidebar.</div>
            <div style="padding:20px" class="center-align">
                <button id="toggle" class="e-btn e-info">Toggle Sidebar</button>
        <!--end of main content declaration -->