-
-
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
[ButtonGroup] Determine first, last and middle buttons to support different elements with correct styling #38520
[ButtonGroup] Determine first, last and middle buttons to support different elements with correct styling #38520
Conversation
Netlify deploy previewhttps://deploy-preview-38520--material-ui.netlify.app/ @material-ui/core: parsed: +0.11% , gzip: +0.12% Bundle size reportDetails of bundle changes (Toolpad) |
boxShadow: 'none', | ||
}), | ||
}, | ||
[`& .${buttonGroupClasses.firstButton},.${buttonGroupClasses.middleButton}`]: { |
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.
@ZeeshanTamboli Instead of exposing the className, how about using just data-*
attribute like:
- data-first-child
- data-last-child
No need for middle because we can use CSS :not
to target middle children like this:
.${buttonGroupClasses.root}:not([data-first-child], [data-last-child])
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.
@siriwatknp I had thought about that and also referred Joy UI's ButtonGroup component code. The reason I added middle class is because then the :not
selector will select the wrapping elements instead of button. As an example, in the case of the Tooltip shown in the CodeSandbox provided in the description it will select the Tooltip's span
elements for:
<ButtonGroup>
<Tooltip title="tooltip">
<Button>Enabled</Button>
</Tooltip>
<Tooltip title="tooltip">
<span>
<Button disabled>Disabled</Button>
</span>
</Tooltip>
<Tooltip title="tooltip">
<span>
<Button disabled>Disabled</Button>
</span>
</Tooltip>
</ButtonGroup>
And span
is also needed to show the tooltip on disabled buttons - https://mui.com/material-ui/react-tooltip/#disabled-elements. Related issue #29514. The :not
selector, however, won't target nested elements, such as a button inside a tooltip.
Regarding exposing classes, offering customization options to users might be a good idea. However, if desired, I could also use data-first-child
, data-middle-child
, and data-last-child
attributes. Let me know your preference.
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.
Alright, let's try data-middle-child
instead of classes so that we don't expose too much API at this point.
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.
@siriwatknp Done.
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.
@siriwatknp, why not classes? We tend to use classes everywhere in Material UI for styling.
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 rolled back to use classes now.
@ZeeshanTamboli Please don't ping the core group for PR reviews that are on sub-product scopes. This creates too much notification noise. Instead, this is a PR for the ButtonGroup, you can ask for a review from one of the maintainers https://www.notion.so/mui-org/Components-Inputs-ecd48c9afe354bda8ecda3e96abc8c3c. Thanks |
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.
Hey @ZeeshanTamboli! sorry for the late review, I left some questions
packages/mui-material/src/ButtonGroup/ButtonGroupButtonContext.ts
Outdated
Show resolved
Hide resolved
packages/mui-material/src/ButtonGroup/ButtonGroupButtonContext.ts
Outdated
Show resolved
Hide resolved
Can this PR be reviewed further? |
The logic looks good to me, but I agree with @michaldudak points:
|
@DiegoAndai I made the changes, switching from data attributes to class names. I've also relocated the styles from the Additionally, I've included unit tests. So, if I understand correctly, these tests are added to ensure that we don't unintentionally introduce breaking changes when modifying the classes, is that right? |
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.
@ZeeshanTamboli thanks for applying the changes 😊
I agree with the specificity change 👍🏼
These tests are added to ensure that we don't unintentionally introduce breaking changes when modifying the classes, is that right?
Exactly.
I've added below another idea that came to mind.
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.
LGTM 🚀
This should go on the highlights of next release, nice improvement!
…ferent elements with correct styling (mui#38520)
Based on point 2 of #29514 (comment).
Fixes #31210
Fixes #29514
Decided to tackle this after reviewing PR #38403.
Before: https://codesandbox.io/s/lively-http-3w24nw?file=/src/App.tsx
After: https://codesandbox.io/s/quizzical-glitter-kgrmyn