-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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][joy] Fix style for single Button #37692
[ButtonGroup][joy] Fix style for single Button #37692
Conversation
[ButtonGroup][joy-ui] fix style for single child
Netlify deploy previewhttps://deploy-preview-37692--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
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.
Thank you for the pull request!
Unfortunately, it doesn't work for the second demo. You can find it at https://codesandbox.io/s/new-hooks-dmz3t2?file=/demo.tsx. The issue might be that the React.Children.count(children)
count for the wrapped Button component could be two.
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.
I think you can use CSS selector :only-child
instead of a new data-single-child
. Here is the change I propose:
diff --git a/packages/mui-joy/src/ButtonGroup/ButtonGroup.tsx b/packages/mui-joy/src/ButtonGroup/ButtonGroup.tsx
index 3c9109e89f..8e07fcfd71 100644
--- a/packages/mui-joy/src/ButtonGroup/ButtonGroup.tsx
+++ b/packages/mui-joy/src/ButtonGroup/ButtonGroup.tsx
@@ -84,7 +84,7 @@ const ButtonGroupRoot = styled('div', {
borderRadius: 'var(--ButtonGroup-radius)',
flexDirection: ownerState.orientation === 'vertical' ? 'column' : 'row',
// first Button or IconButton
- [`& > [data-first-child]`]: {
+ [`& > [data-first-child]:not([data-last-child])`]: {
'--Button-radius': firstChildRadius,
'--IconButton-radius': firstChildRadius,
...(ownerState.orientation === 'horizontal' && {
@@ -109,7 +109,7 @@ const ButtonGroupRoot = styled('div', {
}),
},
// last Button or IconButton
- [`& > [data-last-child]`]: {
+ [`& > [data-last-child]:not([data-first-child]`]: {
'--Button-radius': lastChildRadius,
'--IconButton-radius': lastChildRadius,
...(ownerState.orientation === 'horizontal' && {
@@ -119,7 +119,7 @@ const ButtonGroupRoot = styled('div', {
borderTop: 'var(--ButtonGroup-separatorSize) solid var(--ButtonGroup-separatorColor)',
}),
},
- [`& > :not([data-first-child])`]: {
+ [`& > :not([data-first-child]):not(:only-child)`]: {
'--Button-margin': margin,
'--IconButton-margin': margin,
},
For the second demo, I'd say we should add a doc for |
Good idea with the |
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.
I am not very familiar with Joy UI code but your logic also seems to make sense compared to #37692 (review) and even custom button works without the need of spreading props because the data-attributes are not added for a single button.
Signed-off-by: Zeeshan Tamboli <zeeshan.tamboli@gmail.com>
Signed-off-by: Zeeshan Tamboli <zeeshan.tamboli@gmail.com>
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.
Looks good to me!
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.
👍 Awesome!
[ButtonGroup][joy-ui] fix style for single child
Fixes #37687
Single buttons are now properly styled
Before: https://codesandbox.io/s/exciting-black-y2glhj
After: https://codesandbox.io/s/amazing-sid-pth57n?file=/demo.tsx