-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Improve demos #18981
[Badge] Improve demos #18981
Conversation
2c8bf3e
to
7a8ed11
Compare
No bundle size changes comparing ee46512...fa9e6b2 |
7a8ed11
to
8a7b957
Compare
8a7b957
to
c6e2422
Compare
Browser test was failed with timeout. Could I retry it? |
I don't understand, what problem do the changes solve? |
Changing the appearance of a badge while disappearing animation (like |
Should it be handled in userland? What's the use case for changing the appearance during an animation? |
I think most of the users write Color must be less frequently changed, but writing something like (I checked Google Analytics (which uses different colors for same badge, but maybe different from Material), and it does not animate at disappearing.) |
8d0a5a0
to
d2db5f7
Compare
@ypresto Ok thanks for sharing the use case. I don't think that we should care about the color/variant changes. Regarding the 0 -> 1 jump. I have updated the demo to reproduce it and updated the implementation with a simple patch. If this works for you, I think that it would be great to add a test case (with testing-library, not enzyme). |
d2db5f7
to
356296b
Compare
@ypresto I have sent one commit to focus on the demo only. Regarding the animation problem. I can't wrap my head around a viable solution. Any idea? |
7a8de22
to
fa9e6b2
Compare
I was in new year holidays 🙏
I agree with you. Might better to have demo, but perhaps someone want to fix it can find this PR. 😺 |
@ypresto I hope you had great holidays! :D. |
Oh, it's somewhat legacy and not retrieving sufficient maintenance? reactjs/react-transition-group#429 🤔 But its |
It seems that the documentation has this exact same issue with the notification. Notice the double state change 2 -> 0 -> invisible. cc @mbrookes |
Ah, it was hidden when the popper content covered the icon, so hadn't noticed. What about this diff?: index cf1fcef48..1ddcfe62b 100644
--- a/packages/material-ui/src/Badge/Badge.js
+++ b/packages/material-ui/src/Badge/Badge.js
@@ -171,6 +171,8 @@ const Badge = React.forwardRef(function Badge(props, ref) {
...other
} = props;
+ const [lastContent] = React.useState(badgeContent, []);
+
let invisible = invisibleProp;
if (
@@ -184,6 +186,7 @@ const Badge = React.forwardRef(function Badge(props, ref) {
if (variant !== 'dot') {
displayValue = badgeContent > max ? `${max}+` : badgeContent;
+ displayValue = badgeContent === 0 && !showZero ? lastContent : badgeContent;
}
return ( |
@mbrookes Does it work with consecutive updates? |
It works with the docs +/- demo, but as soon as I posted it, I realised that for the notifications icon, it's still showing showing 0 before transitioning out. 🤷🏽♂️ |
Orignal Title: [Badge] Retain text, color and variant while disappearing
Currently, Badge will apply all appearance immediately even while disappearing transition.
It perhaps causes flicker in some cases like:
<Badge color={hasUrgent ? 'error' : 'secondary'} badgeContent={count}>
Simulating such situation with demo:
docs/src/pages/components/badges/BadgeVisibility.js
This PR fixes that flicker: text, color and variant will be applied at next appearing.