Skip to content

[docs] Show how to target global state classes with CSS Modules #45992

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

Merged
merged 8 commits into from
May 6, 2025

Conversation

RubemMazzetto
Copy link
Contributor

@RubemMazzetto RubemMazzetto commented Apr 24, 2025

Closes #42941

This Pull Request improves the CSS Modules section of the Interoperability guide by documenting how to target custom pseudo-classes such as .Mui-selected.

Changes

  • Adds a example that shows how to combine local CSS module classes with global Material UI state classes.
  • Explains how to use the :global selector to scope styles correctly.
  • Highlights real-world use with a ListItem that conditionally applies custom styles when selected.

Why

This improvement addresses the issue #42941 by providing a clear and actionable solution.

Captura de tela 2025-04-24 020455

@zannager zannager added the docs Improvements or additions to the documentation label Apr 24, 2025
@zannager zannager requested a review from ZeeshanTamboli April 24, 2025 14:35
@mui-bot
Copy link

mui-bot commented Apr 25, 2025

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

@RubemAZ Thanks for the PR.

I think this should be under the "CSS Modules" section in the Interoperability docs: https://mui.com/material-ui/integrations/interoperability/#css-modules.

The "Global CSS" section is for targeting the classnames already provided by the Material UI components whereas the "CSS Modules" is for targeting the custom local classes provided by the user.

So, if we want to target the Material UI classes with local CSS modules classes we need to use the global selector (:global).

Also this section (https://mui.com/material-ui/integrations/interoperability/#deeper-elements-4) already shows using the :global CSS Module selector. It shows doing:

.slider :global .MuiSlider-thumb {
  border-radius: 1px;
}

whereas the following also works:

.slider :global(.MuiSlider-thumb) {
  border-radius: 1px;
}

I think we should modify it to use .slider :global(.MuiSlider-thumb) and also add this new section on targeting .Mui-selected state class and .myListItem local class under this.

@ZeeshanTamboli ZeeshanTamboli changed the title [docs][material-ui] Add support for custom pseudo-classes with CSS Modules [docs] Add support for custom pseudo-classes with CSS Modules Apr 26, 2025
@ZeeshanTamboli ZeeshanTamboli added the customization: css Design CSS customizability label Apr 26, 2025
@ZeeshanTamboli ZeeshanTamboli changed the title [docs] Add support for custom pseudo-classes with CSS Modules [docs] Show how to target custom pseudo-classes with CSS Modules Apr 26, 2025
@RubemMazzetto
Copy link
Contributor Author

@ZeeshanTamboli, thank you for review.

Once the adjustments you requested in the Deeper Elements section have been made, I believe there is no need to maintain this new section. What do you think about this? If you would like to continue with this new section, or if you would like to proceed with reviewing and improving the explanation, I am at your disposal.

@ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli, thank you for review.

Once the adjustments you requested in the Deeper Elements section have been made, I believe there is no need to maintain this new section. What do you think about this? If you would like to continue with this new section, or if you would like to proceed with reviewing and improving the explanation, I am at your disposal.

Thanks, @RubemAZ. I think we should keep the new list item example section and also update the existing Slider section. We can place the new section right below the updated one.

@RubemMazzetto
Copy link
Contributor Author

@ZeeshanTamboli, do you think we need to keep the new section under the Deeper Elements, right?

What do you think about rendering the example list, like the sliders rendered in the following documentation (https://mui.com/material-ui/integrations/interoperability/#deeper-elements-4)?
Something like this: (https://mui.com/material-ui/react-list/#selected-listitem)

@ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli, do you think we need to keep the new section under the Deeper Elements, right?

Yes, under the Deeper Elements section and below the Slider example.

What do you think about rendering the example list, like the sliders rendered in the following documentation (https://mui.com/material-ui/integrations/interoperability/#deeper-elements-4)? Something like this: (https://mui.com/material-ui/react-list/#selected-listitem)

Yes, sounds good 👍

@ZeeshanTamboli ZeeshanTamboli changed the title [docs] Show how to target custom pseudo-classes with CSS Modules [docs] Show how to target global state classes with CSS Modules May 6, 2025
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

@RubemAZ I made the expected changes. Thanks for the PR!

@ZeeshanTamboli ZeeshanTamboli merged commit 932c1eb into mui:master May 6, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: css Design CSS customizability docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs][material-ui] CSS modules customization guide is incomplete
4 participants