[material-ui][Badge] When `showZero={false}` and value is `0` content is not updated

Open
#43,081 2 comments 0 reactions 1 assignee View on GitHub

@DiegoAndai is already working on this.

Since Jul 26, 2024.

Assessment

This issue has not been assessed yet.

Description

scope: badge type: bug
Steps to reproduce

Link to live example: (required)
Demo in Stackblitz : https://stackblitz.com/edit/react-qkjzbj?file=Demo.tsx
Steps:

  1. Inspect .MuiBadge-badge elements in dev tools
  2. Click "Set to 0" and observe
Current behavior
  • For Badge with showZero={false} content of .MuiBadge-badge element will not be updated (will still be 8, depite of element being not visible)
  • For Badge with showZero={true} content of .MuiBadge-badge element will be updated
Expected behavior

I believe this is wrong and content should updated to current value, even if element is not visible

Context

I am using Badge component and while testing if it visually hidden and has zero value when value is changed from anything other than 0 tests are failing because element is hidden but old value is present in the DOM.

Your environment
npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: MuiBadge

Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mui/material-ui

All issues in mui/material-ui

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.