Primeng: Button lose class style after label update with after primeng 9.1.0

Created on 2 Jul 2020  路  8Comments  路  Source: primefaces/primeng

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)

Bug with Primeng 9.1.2 and angular 10:
https://stackblitz.com/edit/github-qbkr34?file=src%2Fapp%2Fapp.component.html

Bug with Primeng 9.1.3 and angular 9:
https://stackblitz.com/edit/github-f3ydbw?file=package.json

Work with Primeng 9.1.0 and angular 9:
https://stackblitz.com/edit/github-f3ydbw-vsqqg3?file=package.json

Current behavior

If label changed dynamically, the style by class is lost.

Just with angular 10 observed, not with 9. I'm not sure if this is an error of Angular or Primeng.

Expected behavior

No style change on update.

Minimal reproduction of the problem with instructions

Use dynamic label update:

What is the motivation / use case for changing the behavior?

Works without problems with Angular 9.
Works without problems with primeng 9.1.0.

Please tell us about your environment:

  • Angular version: 10.0.2

  • PrimeNG version: 9.1.2

  • Browser: Chrome Firefox

  • Language: [all | TypeScript X.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version = 12

LTS-FIXED-9.1.4 defect

Most helpful comment

@Rotzbua yes extactly. this bug exists since primeng v9.1.1 .

this bug was created in this commit: https://github.com/primefaces/primeng/commit/dbe0bd8e9320fa3239e389aba2f61af399ffbd53

    setStyleClass() {
        let styleClass = this.getStyleClass();
        this.el.nativeElement.className = styleClass; // => this line of code overrides all initial css classes
    }

All 8 comments

i have same issue with PrimeNG version: 9.1.2 and Angular version: 9.1.11

I have same issue ... PrimeNG version: 9.1.2 and Angular version: 9.1

I have this problem too. There is a simple solution, but the PrimeNG team does not apply it

PrimeNG team! Please do some thing about this!

@all Thanks for feedback. Updated bug description. Primeng 9.1.0 seems the latest version without this bug.

@Rotzbua yes extactly. this bug exists since primeng v9.1.1 .

this bug was created in this commit: https://github.com/primefaces/primeng/commit/dbe0bd8e9320fa3239e389aba2f61af399ffbd53

    setStyleClass() {
        let styleClass = this.getStyleClass();
        this.el.nativeElement.className = styleClass; // => this line of code overrides all initial css classes
    }

a possible soultion is to hold initial css classes in a private field like this :

    ngAfterViewInit() {
        this._initialStyleClass = this.el.nativeElement.className;
        ....
    }

    private _initialStyleClass : string; // introduce a new field to hold the initial css classes

    setStyleClass() {
        let styleClass = this.getStyleClass();
        this.el.nativeElement.className = styleClass + this._initialStyleClass;
    }

@yigitfindikli We should add it to 9.x LTS as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cyberrranger picture cyberrranger  路  3Comments

SchneMa picture SchneMa  路  3Comments

lilling picture lilling  路  3Comments

jisqaqov picture jisqaqov  路  3Comments

miresk picture miresk  路  3Comments