Skip to content
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

Merged
merged 20 commits into from
Mar 19, 2024

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Feb 24, 2024

@sai6855 sai6855 added docs Improvements or additions to the documentation deprecation New deprecation message package: material-ui Specific to @mui/material component: ButtonGroup The React component. labels Feb 24, 2024
@mui-bot
Copy link

mui-bot commented Feb 24, 2024

@sai6855 sai6855 marked this pull request as draft February 24, 2024 05:30
Comment on lines +120 to +123
'horizontal',
'vertical',
'colorPrimary',
'colorSecondary',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new classes

Comment on lines 41 to 62
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);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests for new classes

@sai6855 sai6855 requested a review from DiegoAndai February 25, 2024 11:51
@sai6855
Copy link
Contributor Author

sai6855 commented Feb 25, 2024

Not reaaly sure why test-types CI is failing, i don't think erros shown here are related to this PR

@sai6855 sai6855 marked this pull request as ready for review February 25, 2024 11:54
@sai6855 sai6855 force-pushed the deprecate-button-group-classes branch from 0a34aaf to 55c9e10 Compare February 25, 2024 12:17
});
});

const selector = `${replacementSelectorPrefix}${deprecatedClass}`;
Copy link
Contributor Author

@sai6855 sai6855 Feb 25, 2024

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

Copy link
Member

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?

Copy link
Contributor Author

@sai6855 sai6855 Feb 29, 2024

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

Copy link
Member

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.

Copy link
Contributor Author

@sai6855 sai6855 Mar 6, 2024

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");

Copy link
Member

@DiegoAndai DiegoAndai Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird, do you think it's matching with MuiButtonGroup-groupedText instead? It shouldn't:

Screenshot 2024-03-07 at 15 32 02

Did this one work?:

new RegExp(`${replacementSelectorPrefix}${deprecatedClass}$`)

Copy link
Contributor Author

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

@sai6855 sai6855 force-pushed the deprecate-button-group-classes branch from 8d0f26c to a17eea0 Compare February 29, 2024 06:05
@sai6855 sai6855 force-pushed the deprecate-button-group-classes branch from a17eea0 to 0a6182b Compare February 29, 2024 07:38
Copy link
Member

@DiegoAndai DiegoAndai left a 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.

@sai6855 sai6855 changed the base branch from master to next March 19, 2024 13:03
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RTM 🎉

@DiegoAndai DiegoAndai merged commit 23c3f46 into mui:next Mar 19, 2024
22 checks passed
pluvio72 pushed a commit to pluvio72/material-ui that referenced this pull request Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ButtonGroup The React component. deprecation New deprecation message docs Improvements or additions to the documentation package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants