Skip to content

Commit

Permalink
Merge pull request #15773 from SoyDiego/15736-fix-button
Browse files Browse the repository at this point in the history
fix(Button):  The icon is not shown
  • Loading branch information
cetincakiroglu authored Jun 13, 2024
2 parents 0389df3 + 45141f4 commit e4b7c69
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/app/components/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,17 @@ export class ButtonDirective implements AfterViewInit, OnDestroy {
let iconElement = DomHandler.findSingle(this.htmlElement, '.p-button-icon');
let labelElement = DomHandler.findSingle(this.htmlElement, '.p-button-label');

if (this.loading && !this.loadingIcon && iconElement) {
iconElement.innerHTML = this.spinnerIcon;
} else if (iconElement?.innerHTML) {
if (this.loading) {
if (!this.loadingIcon && iconElement) {
iconElement.innerHTML = this.spinnerIcon;
} else if (this.loadingIcon && iconElement) {
iconElement.className = `p-button-icon ${this.loadingIcon}`;
}
} else if (this.icon && iconElement) {
iconElement.className = `p-button-icon ${this.icon}`;
} else if (iconElement) {
iconElement.innerHTML = '';
this.createIcon();
}

if (iconElement) {
Expand Down Expand Up @@ -360,7 +367,7 @@ export class ButtonDirective implements AfterViewInit, OnDestroy {
<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'"></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>
Expand Down Expand Up @@ -523,14 +530,21 @@ export class Button implements AfterContentInit {
}

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

if (this.loading) {
iconClasses[`p-button-loading-icon pi-spin ${this.loadingIcon ?? ''}`] = true;
} else if (this.icon) {
iconClasses[this.icon] = true;
}

return iconClasses;
}

get buttonClass() {
Expand Down
20 changes: 20 additions & 0 deletions src/app/showcase/doc/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -22310,6 +22310,26 @@
],
"description": "Callback to invoke when default command button is clicked."
},
{
"name": "onMenuHide",
"parameters": [
{
"name": "value",
"type": "any"
}
],
"description": "Callback to invoke when overlay menu is hidden."
},
{
"name": "onMenuShow",
"parameters": [
{
"name": "value",
"type": "any"
}
],
"description": "Callback to invoke when overlay menu is shown."
},
{
"name": "onDropdownClick",
"parameters": [
Expand Down

0 comments on commit e4b7c69

Please sign in to comment.