-
-
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
[material-ui][ButtonGroup] Deprecate composed classes #41259
Conversation
Netlify deploy previewBundle size reportDetails of bundle changes (Toolpad) |
'horizontal', | ||
'vertical', | ||
'colorPrimary', | ||
'colorSecondary', |
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.
new classes
it('should have groupedColorPrimary classe', () => { | ||
const { container } = render( | ||
<ButtonGroup> | ||
<Button>Hello World</Button> | ||
</ButtonGroup>, | ||
); | ||
const buttonGroup = container.firstChild; | ||
expect(buttonGroup).to.have.class(classes.colorPrimary); | ||
expect(buttonGroup).to.have.class(classes.horizontal); | ||
}); | ||
|
||
it('should have groupedSecondary classe', () => { | ||
const { container } = render( | ||
<ButtonGroup color="secondary"> | ||
<Button>Hello World</Button> | ||
</ButtonGroup>, | ||
); | ||
|
||
const buttonGroup = container.firstChild; | ||
expect(buttonGroup).to.have.class(classes.colorSecondary); | ||
}); | ||
|
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.
tests for new classes
|
0a34aaf
to
55c9e10
Compare
}); | ||
}); | ||
|
||
const selector = `${replacementSelectorPrefix}${deprecatedClass}`; |
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.
Observed an issue with regex approach here (the approach which already merged PR's are using).
when running codemod for .MuiButtonGroup-groupedTextHorizontal
regex matched with .MuiButtonGroup-groupedText
and applied replacementSelector of .MuiButtonGroup-groupedText
which is .MuiButtonGroup-text > .MuiButtonGroup-grouped
instead of applying replaceSelector of .MuiButtonGroup-groupedTextHorizontal
.
So went with absolute equality approach instead of regex equality
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.
The problem with absolute equality is that it won't match when the literal has more classes, for example .Mui-disabled .MuiButtonGroup-groupedTextHorizontal
. We could use regex's $
matcher to match the end of the file, or a dot .
which would denote another class.
new Regex(`${replacementSelectorPrefix}${deprecatedClass}(.|$)`)
Would that work?
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.
The problem with absolute equality is that it won't match when the literal has more classes, for example .Mui-disabled .MuiButtonGroup-groupedTextHorizontal. We could use regex's $ matcher to match the end of the file, or a dot . which would denote another class.
i see, got it.
new RegExp(
${replacementSelectorPrefix}${deprecatedClass}(.|$)
)
This regexp was transforming ('& .MuiButtonGroup-groupedTextHorizontal');
to ("&.MuiButtonGroup-text > .MuiButtonGroup-groupedorizontal");
instead of ("&.MuiButtonGroup-text.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped");
so changed Regexp to new RegExp(
${replacementSelectorPrefix}${deprecatedClass}($))
and it seems like this is working
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'm sorry, my mistake. We must escape the dot as it's a regex symbol for any character. This regex should work:
new Regex(`${replacementSelectorPrefix}${deprecatedClass}(\.| |$)`)
I added the space as well " "
to accommodate for other selectors.
Let me know if that works and sorry for the late reply.
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.
Tried
new RegExp(`${replacementSelectorPrefix}${deprecatedClass}(\.| |$)`)
and
new RegExp(`${replacementSelectorPrefix}${deprecatedClass}(.| |$)`)
both are transforimg ('& .MuiButtonGroup-groupedTextHorizontal');
to ("&.MuiButtonGroup-text > .MuiButtonGroup-groupedorizontal");
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.
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.
Did this one work? new RegExp(
${replacementSelectorPrefix}${deprecatedClass}$
)
Yes, this worked. commit reference: 67e475f
8d0f26c
to
a17eea0
Compare
a17eea0
to
0a6182b
Compare
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 @sai6855, I reviewed and found a couple of details but I think after that this is ready to merge.
Next week, we'll freeze v5 and open the next
branch to release v6 alpha versions. Would you mind waiting until then to merge this? This way, we'll avoid fixing any error in v5 that may have slipped. This is to be extra careful as we'll try not to release any v5 patches after it's frozen. The idea is to use this week to merge only urgent that have to be included in v5. Does that make sense?
If you're on board, I'll ask you to wait a bit longer, and when the next
branch is created next week, point this PR to that branch instead. I'll let you know.
packages/mui-codemod/src/deprecations/button-group-classes/postcss-plugin.js
Outdated
Show resolved
Hide resolved
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.
RTM 🎉
part of #41282
classes api doc: https://deploy-preview-41259--material-ui.netlify.app/material-ui/api/button-group/#classes
migration guide: https://deploy-preview-41259--material-ui.netlify.app/material-ui/migration/migrating-from-deprecated-apis/#buttongroup