Item configuration in Angular Toolbar component
17 Sep 202514 minutes to read
The Toolbar renders by defining an array of items. Items can be constructed with the following built-in item types or custom templates.
Button
Button is the default item type, and renders using the text property.
Properties of the button item type:
| Property | Description |
|---|---|
text |
The text to be displayed for the button. |
id |
The ID of the button to be rendered. If the ID is not provided, an auto ID is generated. |
prefixIcon |
Defines the class used to specify an icon for the button. The icon is positioned before the text if text is available, or the icon alone renders as a button. |
suffixIcon |
Defines the class used to specify an icon for the button. The icon is positioned after the text if text is available. If both prefixIcon and suffixIcon are specified, only prefixIcon is considered. |
width |
Sets the width of the button. |
align |
Specifies the location for aligning Toolbar items. |
Separator
The Separator type adds a vertical separation between the Toolbar’s single or multiple commands.
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='Cut'></e-item>
<e-item text='Copy'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Paste'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Undo'></e-item>
<e-item text='Redo'></e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
}If
Separatoris added as first or last item, it is not visible.
Input
The Input type is only applicable for adding template elements when the template property is defined as an object.
Input type creates an input element internally that acts as the container for Syncfusion input based components.
Note: Set toolbar item type property value as
Inputonly for Input components.
NumericTextBox
-
The
NumericTextBoxcomponent can be included by importing theNumericTextBoxmodule fromej2-inputs. -
Initialize the
NumericTextBoxin template property, where the Toolbar item type is set asInput. -
Related
NumericTextBoxcomponent properties can also be configured as shown below.
new NumericTextBox( { format: 'c2' })DropDownList
-
The
DropDownListcomponent can be included by importing theDropDownListmodule fromej2-dropdowns. -
Initialize the
DropDownListin template property, where the Toolbar item type is set asInput. -
Related
DropDownListcomponent properties can also be configured as shown below.
new DropDownList({ width: 100 })CheckBox
-
The
CheckBoxcomponent can be included by importing theCheckBoxmodule fromej2-buttons. -
Initialize the
CheckBoxin template property, where the Toolbar item type is set asInput. -
Related
CheckBoxcomponent properties can also be configured as shown below.
new CheckBox({ label: 'Checkbox', checked: true })RadioButton
-
The
RadioButtoncomponent can be included by importing theRadioButtonmodule fromej2-buttons. -
Initialize the
RadioButtonin template property, where the Toolbar item type is set asInput. -
Related
RadioButtoncomponent properties can also be configured as shown below.
new RadioButton({ label: 'Radio', name: 'default', checked: true })The above steps apply to all Syncfusion input based components.
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 { NumericTextBoxModule } from '@syncfusion/ej2-angular-inputs'
import { RadioButtonModule } from '@syncfusion/ej2-angular-buttons'
import { CheckBoxModule } from '@syncfusion/ej2-angular-buttons'
import { DropDownListModule } from '@syncfusion/ej2-angular-dropdowns'
import { Component, ViewChild } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';
import { NumericTextBox} from '@syncfusion/ej2-inputs';
import { DropDownList} from '@syncfusion/ej2-dropdowns';
import { CheckBox, RadioButton } from '@syncfusion/ej2-buttons';
@Component({
imports: [
ToolbarModule, TooltipModule, NumericTextBoxModule, RadioButtonModule, CheckBoxModule, DropDownListModule
],
standalone: true,
selector: 'app-container',
template: `
<ejs-toolbar>
<e-items>
<e-item text='Cut'></e-item>
<e-item text='Copy'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Undo'></e-item>
<e-item text='Redo'></e-item>
<e-item type='Input'>
<ng-template #template>
<ejs-numerictextbox format="c2" value="1" width="150"></ejs-numerictextbox>
</ng-template>
</e-item>
<e-item type='Input'>
<ng-template #template>
<ejs-dropdownlist [dataSource]='this.data' width="120" index="2"></ejs-dropdownlist>
</ng-template>
</e-item>
<e-item type='Input'>
<ng-template #template>
<ejs-checkbox label="CheckBox: true" [checked]="true"></ejs-checkbox>
</ng-template>
</e-item>
<e-item type='Input'>
<ng-template #template>
<ejs-radiobutton label='Radio' name='default' checked="true"></ejs-radiobutton>
</ng-template>
</e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
@ViewChild('element') element?: any;
public data: string[] = ['Badminton', 'Basketball', 'Cricket', 'Golf', 'Hockey', 'Rugby'];
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Enabling tab key navigation in Toolbar
The tabIndex property of a Toolbar item enables tab key navigation for the item. By default, users can switch between items using the arrow keys, but the tabIndex property allows switching between items using the Tab and Shift+Tab keys as well.
To use the tabIndex property, set it for each Toolbar item that requires 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:
import { Component, ViewChild } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';
@Component({
selector: 'app-container',
template: `
<ejs-toolbar>
<e-items>
<e-item text='item1' tabIndex=1></e-item>
<e-item text='item2' tabIndex=2></e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
}With the above code, users 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:
import { Component, ViewChild } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';
@Component({
selector: 'app-container',
template: `
<ejs-toolbar>
<e-items>
<e-item text='item1' tabIndex=0></e-item>
<e-item text='item2' tabIndex=0></e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
}In this case, users 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.
Example:
Here is an example of how to use the tabIndex property to enable tab key navigation for a Toolbar component:
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='Cut' tabIndex=0></e-item>
<e-item text='Copy' tabIndex=0></e-item>
<e-item type='Separator'></e-item>
<e-item text='Paste' tabIndex=0></e-item>
<e-item type='Separator'></e-item>
<e-item text='Undo' tabIndex=0></e-item>
<e-item text='Redo' tabIndex=0></e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));With the above code, users can switch between the Toolbar items using the Tab and Shift+Tab keys, and the items will be navigated based on the element order.