Types in Angular Sidebar component
12 Sep 202511 minutes to read
The Sidebar component allows configuration of its expand behavior using the type
property to suit various layout requirements, such as overlaying content or resizing the main content area.
Sidebar expand types
The Sidebar can be set to initialize based on four different types that are consistent with the main component as explained below. When dataBind
is invoked, it immediately applies any pending property changes to the component.
Item | Description |
---|---|
Over |
Sidebar floats over the main content area. |
Push |
Sidebar pushes the main content area aside, appearing side-by-side, and shrinks the main content within the screen width. |
Slide |
Sidebar shifts the main content area’s x and y positions based on the Sidebar width. The main content area is not adjusted to fit within the screen width. |
Auto |
Sidebar with Over type in mobile resolution, and Push type in other higher resolutions. |
Note: The
Auto
type is the default, enabling responsive behavior based on screen size.
The following sample demonstrates the different Sidebar types in action, showcasing their visual and functional distinctions.
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';
@Component({
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>
<div class="center-align">
<button ejs-button id="close" (click)="closeClick()" class="e-btn close-btn">Close Sidebar</button>
</div>
</ejs-sidebar>
<div>
<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>
<div id="maincontent" class="content">
<div>
<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>
<div class="row">
<ejs-radiobutton id='slide' #radio label="Slide" name="type" (change)="changeHandler($event)"></ejs-radiobutton>
</div>
<div class="row">
<ejs-radiobutton id='over' #radio label="Over" name="type" (change)="changeHandler($event)"></ejs-radiobutton>
</div>
<div class="row">
<ejs-radiobutton id='auto' #radio label="Auto" name="type" (change)="changeHandler($event)"></ejs-radiobutton>
</div>
</div>
</div>
</div>
</div>`
})
export class AppComponent {
@ViewChild('sidebar') sidebar?: SidebarComponent;
@ViewChild('togglebtn') togglebtn?: ButtonComponent;
public type: string = 'Push';
public target: string = '.content';
public onCreated(args: any) {
(this.sidebar as SidebarComponent).element.style.visibility = '';
}
btnClick(){
if((this.togglebtn as ButtonComponent).element.classList.contains('e-active')){
(this.togglebtn as ButtonComponent).content = 'Open';
this.sidebar?.hide();
}
else{
(this.togglebtn as ButtonComponent).content = 'Close';
this.sidebar?.show();
}
}
closeClick() {
this.sidebar?.hide();
(this.togglebtn as ButtonComponent).element.classList.remove('e-active');
(this.togglebtn as ButtonComponent).content = 'Open'
}
// change the togglebtn state
changestate() {
if((this.sidebar as SidebarComponent).type == 'Auto'){
(this.togglebtn as ButtonComponent).element.classList.add('e-active');
(this.togglebtn as ButtonComponent).content = 'close'
}
else{
(this.togglebtn as ButtonComponent).element.classList.remove('e-active');
(this.togglebtn as ButtonComponent).content = 'Open';
}
}
changeHandler(args: any) : void {
if(args.event.target.ej2_instances[0].label == 'Over') {
(this.sidebar as SidebarComponent).type = 'Over';
} else if (args.event.target.ej2_instances[0].label == 'Push') {
(this.sidebar as SidebarComponent).type = 'Push';
} else if (args.event.target.ej2_instances[0].label == 'Slide') {
(this.sidebar as SidebarComponent).type = 'Slide';
} else {
(this.sidebar as SidebarComponent).type = 'Auto';
}
this.changestate();
this.sidebar?.dataBind();
}
}
@import 'node_modules/@syncfusion/ej2-base/styles/material.css';
@import 'node_modules/@syncfusion/ej2-angular-base/styles/material.css';
@import 'node_modules/@syncfusion/ej2-angular-navigations/styles/material.css';
@import 'node_modules/@syncfusion/ej2-angular-buttons/styles/material.css';
@import 'node_modules/@syncfusion/ej2-angular-lists/styles/material.css';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));