-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[ButtonGroup] Fix rendering with conditional elements #38989
[ButtonGroup] Fix rendering with conditional elements #38989
Conversation
Netlify deploy previewhttps://deploy-preview-38989--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
Not sure about this one, @mnajdova what do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's figure out the copy from Chakra first.
The code looks good, we don't need to include the source of where we copied it, it's not likely that we will need to backport changes in the future. The util itself looks good |
Fixes #38978
Before: https://stackblitz.com/edit/stackblitz-starters-nykpki
After: https://codesandbox.io/s/material-ui-cra-ts-forked-4xh5j7
The issue arises for conditional elements because
React.Children.count(childrenParam
) also counts empty nodes, causing problems with applying the wrong positioning classes and thus resulting in incorrect styling. To avoid this, we can useReact.Children.toArray
, which excludes empty nodes.I've also created a utility method to get valid React elements which is directly copied from Chakra UI source code (let me know if this is fine) so that it can be reused in other MUI packages.
(Note: This bug is also present in Joy UI ButtonGroup component.)