Popup items in Angular Split button component
27 Apr 20247 minutes to read
Icons
The Popup action item have an icon or image to provide visual representation of the action. To place the icon on a popup item, set the iconCss
property to e-icons
with the required icon CSS. By default, the icon is positioned to the left side of the popup action item.
In the following sample, the icons for Cut, Copy and Paste menu items are
added using the iconCss property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SplitButtonModule } from '@syncfusion/ej2-angular-splitbuttons'
import { Component } from '@angular/core';
import { ItemModel } from '@syncfusion/ej2-angular-splitbuttons';
@Component({
imports: [
SplitButtonModule
],
standalone: true,
selector: 'app-root',
template: `<div class="e-section-control">
<ejs-splitbutton content="Paste" iconCss ="e-sb-icons e-paste"[items]='items'></ejs-splitbutton></div>`
})
export class AppComponent {
public items: ItemModel[] = [
{
text: 'Cut',
iconCss: 'e-sb-icons e-cut'
},
{
text: 'Copy',
iconCss: 'e-icons e-copy'
},
{
text: 'Paste',
iconCss: 'e-sb-icons e-paste'
}
];
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Template
Item Templating
Popup items can be customized by using the beforeItemRender
event. The item render event triggers while rendering each Popup action item. The event argument will be used to identify the action item and customize it based on the requirement.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SplitButtonModule } from '@syncfusion/ej2-angular-splitbuttons'
import { Component } from '@angular/core';
import { ItemModel, MenuEventArgs } from '@syncfusion/ej2-angular-splitbuttons';
import { enableRipple, createElement } from '@syncfusion/ej2-base';
@Component({
imports: [
SplitButtonModule
],
standalone: true,
selector: 'app-root',
template: `<div class="e-section-control">
<!-- To Render splitbutton. -->
<ejs-splitbutton iconCss ="e-sb-icons e-paste" [items]='items' (beforeItemRender)='addClass($event)'></ejs-splitbutton></div>`
})
export class AppComponent {
public items: ItemModel[] = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}
];
public addClass(args: MenuEventArgs) {
let shortCutSpan: HTMLElement = createElement('span');
let text: string | any = args.item.text;
args.element.appendChild(shortCutSpan);
shortCutSpan.setAttribute('class','shortcut');
let clsName: string = (text == 'Copy') ? 'e-icons' : 'e-sb-icons';
shortCutSpan.classList.add(clsName);
(text === 'Cut') ? shortCutSpan.classList.add('e-cut') : (text === 'Paste') ? shortCutSpan.classList.add('e-paste') : shortCutSpan.classList.add('e-copy');
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Popup Templating
The whole popup can be customized as per the requirement. In the following example, the popup can be customized by handling it in target
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SplitButtonModule } from '@syncfusion/ej2-angular-splitbuttons'
import { Component } from '@angular/core';
@Component({
imports: [
SplitButtonModule
],
standalone: true,
selector: 'app-root',
template: `<div class="e-section-control">
<!-- To Render splitbutton. -->
<div id='dropdowntarget'>
<div id= "first">
<div id='black'></div>
<div id='red'></div>
<div id='green'></div>
<div id='gray'></div>
<div id='blue'></div>
<div id='violet'></div>
<div id='brown'></div>
<div id='darkgoldenrod'></div>
<div id='aquamarine'></div>
</div>
</div>
<ejs-splitbutton iconCss ="e-sb-icons e-color" target="#dropdowntarget"></ejs-splitbutton></div>`
})
export class AppComponent {
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));