Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge directive with badgeDisabled condition not working #12736

Closed
urielzen opened this issue Mar 10, 2023 · 5 comments · Fixed by #12739
Closed

Badge directive with badgeDisabled condition not working #12736

urielzen opened this issue Mar 10, 2023 · 5 comments · Fixed by #12739
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@urielzen
Copy link

Describe the bug

The following does not work when user.notifications changes value to/from zero.

<i class="pi pi-bell" pBadge [value]="user.notifications" [badgeDisabled]="user.notifications === 0"></i>

If the initial result from user.notifications === 0 is true, then the badge will remain hidden even if the value of user.notifications changes, so user.notifications === 0 result is updated to false, the badge is still hidden, but at that point should be shown.

Environment

PrimeNG 14.2.3

Reproducer

No response

Angular version

14

PrimeNG version

14.2.3

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

16.16.0

Browser(s)

Chrome

Steps to reproduce the behavior

No response

Expected behavior

badgeDisabled should reevaluate when a new value is passed to it.

@urielzen urielzen added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 10, 2023
@RedWings-R
Copy link

RedWings-R commented Mar 31, 2023

I have this bug too.

<li class="topbar-profile" pBadge [value]="nbNotifications.toString()" [badgeDisabled]="nbNotifications == 0">
    <button type="button" class="p-link" (click)="onProfileButtonClick()">
        <img src="assets/layout/images/avatar.png" alt="Profile" />
    </button>
</li>

If i remove the [badgeDisabled]="nbNotifications == 0" the value never change.

<li class="topbar-profile" pBadge [value]="nbNotifications.toString()">
    <button type="button" class="p-link" (click)="onProfileButtonClick()">
        <img src="assets/layout/images/avatar.png" alt="Profile" />
    </button>
</li>

onProfileButtonClick() {
    this.nbNotifications = this.nbNotifications++;
    // this.layoutService.showProfileSidebar();
}

@Triskae
Copy link

Triskae commented Apr 27, 2023

Yep same here ! Here's a repro repo.
Link

@ericvaroto
Copy link

Hello, i'm facing the same issue, cannot hide the badge in my notification icon.
Do you have any ideia when we will have the fix deployed?

Thanks

@diedel
Copy link

diedel commented Sep 9, 2023

You can use the p-overlay-badge style class as a workaround:

<span class="p-overlay-badge">
    <i class="pi pi-bell"></i>
    <p-badge *ngIf="user.notifications > 0" [value]="user.notifications"></p-badge>
</span>

@riker09
Copy link
Contributor

riker09 commented Jan 5, 2024

I confirm that the workaround provided by @diedel works. However, I would prefer the p-badge directive to work with dynamic values if that is possible. If not the documentation should receive at least a warning or hint of some kind so other developers don't have to find this GitHub issue first for a solution.

@cetincakiroglu cetincakiroglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Apr 19, 2024
@cetincakiroglu cetincakiroglu added this to the 17.14.0 milestone Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants