Set command customization in Angular Toolbar component
22 Sep 20252 minutes to read
The htmlAttributes
property of the Toolbar item enables comprehensive customization by setting HTML attributes such as ‘ID’, ‘class’, ‘style’, and ‘role’ for individual toolbar commands.
When applying style attributes through htmlAttributes
, any existing style attributes with the same names will be replaced with the new values. However, the class
attribute behaves differently - new CSS classes are appended to existing classes rather than replacing them, ensuring that previously applied styles are preserved.
For simplified CSS class management, the Toolbar item cssClass
property provides a dedicated approach to add single or multiple CSS classes to toolbar commands. Use cssClass
for straightforward styling scenarios and htmlAttributes
when you need to set additional HTML attributes beyond just CSS classes.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ToolbarModule } from '@syncfusion/ej2-angular-navigations'
import { TooltipModule } from '@syncfusion/ej2-angular-popups'
import { Component, ViewChild } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';
@Component({
imports: [
ToolbarModule, TooltipModule
],
standalone: true,
selector: 'app-container',
template: `
<ejs-toolbar>
<e-items>
<e-item text='Bold' [htmlAttributes] = 'boldAttribute'></e-item>
<e-item text='Italic' [htmlAttributes] = 'italicAttribute'></e-item>
<e-item text='Underline' [htmlAttributes] = 'underAttribute'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Uppercase' cssClass = 'e-txt-casing'></e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
@ViewChild('element') element?: any;
public boldAttribute: any = { 'class': 'custom_bold', 'id': 'itemId' };
public italicAttribute: any = { 'class': 'custom_italic' };
public underAttribute: any = { 'class': 'custom_underline' };
ngAfterViewInit() {
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));