Variations in Angular Sidebar component

27 Apr 202410 minutes to read

The Sidebar component’s expand behaviour can be modified based on the purpose of use.

Expanding types of Sidebar

The Sidebar can be set to initialize based on four different types that are consistent with the main component as explained below.

Item Description
Over Sidebar floats over the main content area.
Push Sidebar pushes the main content area to appear side-by-side, and shrinks the main content within the screen width.
Slide Sidebar translates the x and y positions of main content area based on the Sidebar width. The main content area will not be adjusted within the screen width.
Auto Sidebar with Over type in mobile resolution, and Push type in other higher resolutions.

Auto is the default expand mode.

In the following sample, the types of Sidebar are demonstrated.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SidebarModule } from '@syncfusion/ej2-angular-navigations'
import { ButtonModule, RadioButtonModule  } from '@syncfusion/ej2-angular-buttons'

import { Component, ViewChild  } from '@angular/core';
import { SidebarComponent } from '@syncfusion/ej2-angular-navigations';
import { ButtonComponent, RadioButtonComponent } from '@syncfusion/ej2-angular-buttons';

imports: [
        SidebarModule, ButtonModule, RadioButtonModule 

standalone: true,
    selector: 'app-root',
    styleUrls: ['./app.component.css'],
    template: `  <ejs-sidebar id="default-sidebar" #sidebar [type]='type' [target]='target' (created)="onCreated($event)" style="visibility: hidden">
                        <div class="title"> Sidebar content</div>
                        <div class="sub-title">
                            Click the button to close the Sidebar.
                        <div class="center-align">
                            <button ejs-button id="close" (click)="closeClick()" class="e-btn close-btn">Close Sidebar</button>
                    <div id="head">
                        <button ejs-button id="toggle" #togglebtn cssClass="e-flat" iconCss="e-icons burg-icon" isToggle="true" (click)="btnClick()" content="Open"></button>
                    <div id="maincontent" class="content">
                            <div class="title">Main content</div>
                            <div class="rows">
                                <div class="row">
                                    <ejs-radiobutton id='push' #radio label="Push" name="type" checked="true" (change)="changeHandler($event)"></ejs-radiobutton>
                                <div class="row">
                                    <ejs-radiobutton id='slide' #radio label="Slide" name="type" (change)="changeHandler($event)"></ejs-radiobutton>
                                <div class="row">
                                    <ejs-radiobutton id='over' #radio label="Over" name="type"  (change)="changeHandler($event)"></ejs-radiobutton>
                                <div class="row">
                                    <ejs-radiobutton id='auto' #radio label="Auto" name="type" (change)="changeHandler($event)"></ejs-radiobutton>
export class AppComponent {
    onCreated($event: any) {
    @ViewChild('sidebar') sidebar?: SidebarComponent;
    @ViewChild('togglebtn') togglebtn?: ButtonComponent;

    public type: string = 'Push';
    public target: string = '.content';
        if((this.togglebtn as ButtonComponent).element.classList.contains('e-active')){
            (this.togglebtn as ButtonComponent).content = 'Open';
            (this.togglebtn as ButtonComponent).content = 'Close';
    closeClick() {
        (this.togglebtn as ButtonComponent).element.classList.remove('e-active');
        (this.togglebtn as ButtonComponent).content = 'Open'
    changeHandler(args: any) : void {
        if([0].label == 'Over') {
            (this.sidebar as SidebarComponent).type = 'Over';
        } else if ([0].label == 'Push') {
            (this.sidebar as SidebarComponent).type = 'Push';
        } else if ([0].label == 'Slide') {
            (this.sidebar as SidebarComponent).type = 'Slide';
        } else {
            (this.sidebar as SidebarComponent).type = 'Auto';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));