Skip to content

Commit

Permalink
Fixes #15582 - Button | Remove wrapper span element from icon templates
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed May 15, 2024
1 parent 4154d61 commit 1562077
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/app/components/button/button.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NgClass } from '@angular/common';
import { TemplateRef } from '@angular/core';

/**
Expand All @@ -12,9 +13,19 @@ export interface ButtonTemplates {
/**
* Custom template of icon.
*/
icon(): TemplateRef<any>;
icon(context: {
/**
* Icon class.
*/
class: NgClass;
}): TemplateRef<NgClass>;
/**
* Custom template of loadingicon.
*/
loadingicon(): TemplateRef<any>;
loadingicon(context: {
/**
* Icon class.
*/
class: NgClass;
}): TemplateRef<NgClass>;
}
11 changes: 4 additions & 7 deletions src/app/components/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,14 @@ export class ButtonDirective implements AfterViewInit, OnDestroy {
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
<ng-container *ngIf="loading">
<ng-container *ngIf="!loadingIconTemplate">
<span *ngIf="loadingIcon" [class]="'p-button-loading-icon pi-spin ' + loadingIcon" [ngClass]="iconClass()" [attr.aria-hidden]="true" [attr.data-pc-section]="'loadingicon'"></span>
<span *ngIf="loadingIcon" [ngClass]="iconClass()" [attr.aria-hidden]="true" [attr.data-pc-section]="'loadingicon'"></span>
<SpinnerIcon *ngIf="!loadingIcon" [styleClass]="spinnerIconClass()" [spin]="true" [attr.aria-hidden]="true" [attr.data-pc-section]="'loadingicon'" />
</ng-container>
<span *ngIf="loadingIconTemplate" class="p-button-loading-icon" [ngClass]="iconClass()" [attr.aria-hidden]="true" [attr.data-pc-section]="'loadingicon'">
<ng-template *ngTemplateOutlet="loadingIconTemplate"></ng-template>
</span>
<ng-template [ngIf]="loadingIconTemplate" *ngTemplateOutlet="loadingIconTemplate; context: { class: iconClass() }"></ng-template>
</ng-container>
<ng-container *ngIf="!loading">
<span *ngIf="icon && !iconTemplate" [class]="icon" [ngClass]="iconClass()" [attr.data-pc-section]="'icon'"></span>
<span *ngIf="!icon && iconTemplate" [ngClass]="iconClass()" [attr.data-pc-section]="'icon'">
<ng-template [ngIf]="!icon" *ngTemplateOutlet="iconTemplate"></ng-template>
</span>
<ng-template [ngIf]="!icon && iconTemplate" *ngTemplateOutlet="iconTemplate; context: { class: iconClass() }"></ng-template>
</ng-container>
<span class="p-button-label" [attr.aria-hidden]="icon && !label" *ngIf="!contentTemplate && label" [attr.data-pc-section]="'label'">{{ label }}</span>
<span [ngClass]="badgeStyleClass()" [class]="badgeClass" *ngIf="!contentTemplate && badge" [attr.data-pc-section]="'badge'">{{ badge }}</span>
Expand Down Expand Up @@ -525,6 +521,7 @@ export class Button implements AfterContentInit {

iconClass() {
return {
[`p-button-loading-icon pi-spin ${this.loadingIcon ?? ''}`]: this.loading,
'p-button-icon': true,
'p-button-icon-left': this.iconPos === 'left' && this.label,
'p-button-icon-right': this.iconPos === 'right' && this.label,
Expand Down

0 comments on commit 1562077

Please sign in to comment.