Skip to content

Commit

Permalink
Fixed #9482 - Button | Renders empty label when the label is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 8, 2022
1 parent 954104d commit 8832a90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/app/components/button/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
justify-content: center;
}

.p-button-icon-only .p-button-label {
.p-button-icon-only:after {
content: 'p';
visibility: hidden;
clip: rect(0 0 0 0);
width: 0;
flex: 0 0 auto;
}

.p-button-vertical {
Expand Down Expand Up @@ -65,4 +66,4 @@
.p-buttonset .p-button:focus {
position: relative;
z-index: 1;
}
}
27 changes: 14 additions & 13 deletions src/app/components/button/button.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NgModule, Directive, Component, ElementRef, EventEmitter, AfterViewInit, Output, OnDestroy, Input, ChangeDetectionStrategy, ViewEncapsulation, ContentChildren, AfterContentInit, TemplateRef, QueryList } from '@angular/core';
import { DomHandler } from 'primeng/dom';
import { CommonModule } from '@angular/common';
import { RippleModule } from 'primeng/ripple';
import { AfterContentInit, AfterViewInit, ChangeDetectionStrategy, Component, ContentChildren, Directive, ElementRef, EventEmitter, Input, NgModule, OnDestroy, Output, QueryList, TemplateRef, ViewEncapsulation } from '@angular/core';
import { PrimeTemplate } from 'primeng/api';
import { DomHandler } from 'primeng/dom';
import { RippleModule } from 'primeng/ripple';

type ButtonIconPosition = 'left' | 'right' | 'top' | 'bottom';

Expand Down Expand Up @@ -37,16 +37,17 @@ export class ButtonDirective implements AfterViewInit, OnDestroy {
this.createIconEl();
}

let labelElement = document.createElement('span');
if (this.icon && !this.label) {
labelElement.setAttribute('aria-hidden', 'true');
}
labelElement.className = 'p-button-label';
if (this.label) {
let labelElement = document.createElement('span');
if (this.icon && !this.label) {
labelElement.setAttribute('aria-hidden', 'true');
}
labelElement.className = 'p-button-label';
labelElement.appendChild(document.createTextNode(this.label));

if (this.label) labelElement.appendChild(document.createTextNode(this.label));
else labelElement.innerHTML = ' ';
this.el.nativeElement.appendChild(labelElement);
}

this.el.nativeElement.appendChild(labelElement);
this.initialized = true;
}

Expand Down Expand Up @@ -118,7 +119,7 @@ export class ButtonDirective implements AfterViewInit, OnDestroy {
this._label = val;

if (this.initialized) {
DomHandler.findSingle(this.el.nativeElement, '.p-button-label').textContent = this._label || ' ';
DomHandler.findSingle(this.el.nativeElement, '.p-button-label').textContent = this._label;

if (this.loading || this.icon) {
this.setIconClass();
Expand Down Expand Up @@ -196,7 +197,7 @@ export class ButtonDirective implements AfterViewInit, OnDestroy {
*ngIf="!contentTemplate && (icon || loading)"
[attr.aria-hidden]="true"
></span>
<span class="p-button-label" [attr.aria-hidden]="icon && !label" *ngIf="!contentTemplate">{{ label || '&nbsp;' }}</span>
<span class="p-button-label" [attr.aria-hidden]="icon && !label" *ngIf="!contentTemplate && label">{{ label }}</span>
<span [ngClass]="badgeStyleClass()" [class]="badgeClass" *ngIf="!contentTemplate && badge">{{ badge }}</span>
</button>
`,
Expand Down

0 comments on commit 8832a90

Please sign in to comment.