SplitButtonSplitButton groups a set of commands in an overlay with a default command.

SplitButton - 图1

Documentation

Import

  1. import {SplitButtonModule} from 'primeng/splitbutton';
  2.  

Getting Started

SplitButton has a default command button and a collection of menuitems to be displayed in an overlay.

  1. <p-splitButton label="Save" icon="pi pi-check" (onClick)="save()" [model]="items"></p-splitButton>
  2.  

Animation Configuration

Transition of the open and hide animations can be customized using the showTransitionOptions and hideTransitionOptions properties, example below disables the animations altogether.

  1. <p-splitButton [showTransitionOptions]="'0ms'" [hideTransitionOptions]="'0ms'" label="Save" icon="pi pi-check" (onClick)="save()" [model]="items"></p-splitButton>
  2.  

MenuModel API

SplitButton uses the common menumodel api to define its items, visit MenuModel API for details.

Properties

NameTypeDefaultDescription
labelstringnullText of the button.
iconstringnullName of the icon.
iconPosstringleftPosition of the icon, valid values are "left" and "right".
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
menuStylestringnullInline style of the overlay menu.
menuStyleClassstringnullStyle class of the overlay menu.
appendToanynullTarget element to attach the overlay, valid values are "body" or a local ng-template variable of another element.
disabledbooleanfalseWhen present, it specifies that the component should be disabled.
tabindexnumbernullIndex of the element in tabbing order.
dirstringnullIndicates the direction of the element.
showTransitionOptionsstring225ms ease-outTransition options of the show animation.
hideTransitionOptionsstring195ms ease-inTransition options of the hide animation.

Events

NameParametersDescription
onClickevent: browser eventCallback to invoke when default command button is clicked.
onDropdownClickevent: browser eventCallback to invoke when dropdown button is clicked.

Severity

Different color options are available to define severity levels.

  • .ui-button-secondary
  • .ui-button-success
  • .ui-button-info
  • .ui-button-warning
  • .ui-button-danger
  1. <p-splitButton label="Save" icon="pi pi-check" [model]="items" styleClass="ui-button-warning"></p-splitButton>
  2.  

Styling

Following is the list of structural style classes, for theming classes visit theming page. SplitButton uses button and menu components internally, refer to their documentation for the detailed style list.

NameElement
ui-splitbuttonContainer element.
ui-splitbutton-buttonDropdown button.
ui-menuOverlay menu.

Dependencies

None.

Source

View on GitHub

  1. <p-toast [style]="{marginTop: '80px'}"></p-toast>
  2. <h3 class="first">Basic</h3>
  3. <p-splitButton label="Save" icon="pi pi-file" (onClick)="save('info')" [model]="items"></p-splitButton>
  4. <h3>Severities</h3>
  5. <p-splitButton label="Save" icon="pi pi-file" (onClick)="save('info')" [model]="items" styleClass="ui-button-secondary"></p-splitButton>
  6. <p-splitButton label="Save" icon="pi pi-file" (onClick)="save('success')" [model]="items" styleClass="ui-button-success"></p-splitButton>
  7. <p-splitButton label="Save" icon="pi pi-file" (onClick)="save('info')" [model]="items" styleClass="ui-button-info"></p-splitButton>
  8. <p-splitButton label="Save" icon="pi pi-file" (onClick)="save('warn')" [model]="items" styleClass="ui-button-warning"></p-splitButton>
  9. <p-splitButton label="Save" icon="pi pi-file" (onClick)="save('error')" [model]="items" styleClass="ui-button-danger"></p-splitButton>
  10. <h3>RTL</h3>
  11. <p-splitButton label="Save" icon="pi pi-file" (onClick)="save('info')" [model]="items" dir="rtl"></p-splitButton>
  12.  
  1. export class SplitButtonDemo implements OnInit {
  2. items: MenuItem[];
  3. constructor(private messageService: MessageService) {}
  4. ngOnInit() {
  5. this.items = [
  6. {label: 'Update', icon: 'pi pi-refresh', command: () => {
  7. this.update();
  8. }},
  9. {label: 'Delete', icon: 'pi pi-times', command: () => {
  10. this.delete();
  11. }},
  12. {label: 'Angular.io', icon: 'pi pi-info', url: 'http://angular.io'},
  13. {label: 'Setup', icon: 'pi pi-cog', routerLink: ['/setup']}
  14. ];
  15. }
  16. save(severity: string) {
  17. this.messageService.add({severity:severity, summary:'Success', detail:'Data Saved'});
  18. }
  19. update() {
  20. this.messageService.add({severity:'success', summary:'Success', detail:'Data Updated'});
  21. }
  22. delete() {
  23. this.messageService.add({severity:'success', summary:'Success', detail:'Data Deleted'});
  24. }
  25. }
  26.