Header in Angular Chat UI component
23 Aug 202524 minutes to read
Header visibility
The showHeader property enables or disables the Chat header. When enabled, the header can display a title and an icon using the headerText and headerIconCss properties, respectively.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [showHeader]="false">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Setting header text
The headerText property sets the title displayed in the header, typically used for a username or group name to provide context for the conversation.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" headerText="Michale">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Customizing the header icon
The headerIconCss property applies custom CSS classes to style the header icon.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" headerIconCss="e-icons e-people">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Toolbar
The Chat toolbar can be configured by defining a collection of items in the headerToolbar property. Each item in the collection configures a specific toolbar element.
Configuring toolbar items
Toolbar items can be configured with the following properties to control their appearance and behavior.
Icon
The iconCss property customizes a toolbar item by applying a specific icon class.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [{ iconCss: 'e-icons e-menu', align: 'Right' }]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Item type
You can change the header toolbar item type by using the type property. The type supports three types of items such as Button, Separator and Input. By default, the type is Button.
The type property defines the type of toolbar item. Supported values are Button, Separator, and Input, with Button being the default.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [{ iconCss: 'e-icons e-refresh', align: 'Right', type: 'Button' }]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Text
The text property sets the display text for a toolbar item.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [{ text: 'Log Out', align: 'Right' }]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Visibility
The visible property shows or hides a toolbar item. The default value is true.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [
{ iconCss: 'e-icons e-refresh', align: 'Right', visible: false },
{ iconCss: 'e-icons e-user', align: 'Right' }
]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Disabled state
The disabled property disables a toolbar item. The default value is false.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [
{ iconCss: 'e-icons e-refresh', align: 'Right', disabled: true },
{ iconCss: 'e-icons e-user', align: 'Right' }
]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Tooltip
The tooltip property sets the text that appears when a user hovers over a toolbar item.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [{ iconCss: 'e-icons e-refresh', align: 'Right', tooltip: 'Refresh' }]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Custom CSS class
The cssClass property applies one or more custom CSS classes to a toolbar item for advanced styling.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [ { iconCss: 'e-icons e-user', align: 'Right', cssClass: 'custom-btn' } ]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>#loader {
color: #008cff;
height: 40px;
width: 30%;
position: absolute;
top: 45%;
left: 45%;
}Alignment
The align property positions a toolbar item. Supported values are Left, Center, and Right, with Left being the default.
In the following example, the align property for the toolbar item is set to Right.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [{ iconCss: 'e-icons e-menu', align: 'Right' }]
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>Enabling tab key navigation in toolbar
You can use the tabIndex property of a Toolbar item to enable tab key navigation for the item. By default, the user can switch between items using the arrow keys, but the tabIndex property allows you to switch between items using the Tab and Shift+Tab keys as well.
To use the tabIndex property, set it for each Toolbar item which you want to enable tab key navigation. The tabIndex property should be set to a positive integer value. A value of 0 or a negative value will disable tab key navigation for the item.
For example, to enable tab key navigation for two Toolbar items you can use the following code:
import { Component, ViewChild } from '@angular/core';
import { ChatUIComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div ejs-chatui #chatUI [headerToolbar]="headerToolbar"></div>`
})
export class AppComponent {
@ViewChild('chatUIComponent')
public chatUIComponent!: ChatUIComponent;
public headerToolbar: ToolbarSettingsModel = {
items: [
{ text: "Item 1", tabIndex: 1 },
{ text: "Item 2", tabIndex: 2 }
]
};
}With the above code, the user can switch between the two Toolbar items using the Tab and Shift+Tab keys, in addition to using the arrow keys. The items will be navigated in the order specified by the tabIndex values.
If you set the tabIndex value to 0 for all Toolbar items, tab key navigation will be based on the element order rather than the tabIndex values. For example:
import { Component, ViewChild } from '@angular/core';
import { ChatUIComponent, ToolbarSettingsModel } from '@syncfusion/ej2-angular-interactive-chat';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div ejs-chatui #chatUI [headerToolbar]="headerToolbar"></div>`
})
export class AppComponent {
@ViewChild('chatUIComponent')
public chatUIComponent!: ChatUIComponent;
public headerToolbar: ToolbarSettingsModel = {
items: [
{ text: "Item 1", tabIndex: 0 },
{ text: "Item 2", tabIndex: 0 }
]
};
}In this case, the user can switch between the two Toolbar items using the Tab and Shift+Tab keys, and the items will be navigated in the order in which they appear in the DOM.
Setting template
You can use the template property to add custom toolbar item in the Chat UI component.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { DropDownButton } from '@syncfusion/ej2-angular-splitbuttons';
import { UserModel, ToolbarSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [
{
type: 'Input', align: 'Right',
template: '<button id="ddMenu"></button>'
}
]
};
public dropdownItems = [
{
text: 'Info'
},
{
text: 'Search'
},
{
text: 'Add to list'
},
{
text: 'Mute'
}
];
public created = () => {
var dropdown: DropDownButton = new DropDownButton({
items: this.dropdownItems,
content: 'Menu',
iconCss: 'e-icons e-menu',
cssClass: "custom-dropdown"
}, '#ddMenu');
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar" (created)="created()">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>#loader {
color: #008cff;
height: 40px;
width: 30%;
position: absolute;
top: 45%;
left: 45%;
}Click event
The itemClick event, defined within the toolbarSettings property, triggers when a user clicks a toolbar item. It returns the item that was clicked.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, ToolbarSettingsModel, ToolbarItemClickedEventArgs } from '@syncfusion/ej2-interactive-chat';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public michaleUserModel: UserModel = { user: 'Michale Suyama', id: 'user2' };
public headerToolbar: ToolbarSettingsModel = {
items: [{ iconCss: 'e-icons e-refresh', align: 'Right' }],
itemClicked: (args: ToolbarItemClickedEventArgs) => {
// Your required action here
}
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="chatui" ejs-chatui [user]="currentUserModel" [headerToolbar]="headerToolbar">
<e-messages>
<e-message text="Hi Michale, are we on track for the deadline?" [author]="currentUserModel"></e-message>
<e-message text="Yes, the design phase is complete." [author]="michaleUserModel"></e-message>
<e-message text="I’ll review it and send feedback by today." [author]="currentUserModel"></e-message>
</e-messages>
</div>