Variations in Angular Sidebar component

4 Apr 202310 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 { Component, ViewChild  } from '@angular/core';
import { SidebarComponent } from '@syncfusion/ej2-angular-navigations';
import { ButtonComponent, RadioButtonComponent } from '@syncfusion/ej2-angular-buttons';

    selector: 'app-root',
    styleUrls: ['app/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 {
    @ViewChild('sidebar') sidebar: SidebarComponent;
    @ViewChild('togglebtn') togglebtn: ButtonComponent;

    public type: string = 'Push';
    public target: string = '.content';
            this.togglebtn.content = 'Open';
            this.togglebtn.content = 'Close';
    closeClick() {
         this.togglebtn.content = 'Open'
    changeHandler(args: any) : void {
        if([0].label == 'Over') {
            this.sidebar.type = 'Over';
        } else if ([0].label == 'Push') {
             this.sidebar.type = 'Push';
        } else if ([0].label == 'Slide') {
             this.sidebar.type = 'Slide';
        } else {
             this.sidebar.type = 'Auto';
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 { AppComponent } from './app.component';

 * Module
    imports: [
        SidebarModule, ButtonModule, RadioButtonModule 
    declarations: [AppComponent],
    bootstrap: [AppComponent]
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';