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

Removing a css property from the theme (override) without impacting another #36092

Open
2 tasks done
RemyMachado opened this issue Feb 7, 2023 · 5 comments
Open
2 tasks done
Assignees
Labels
component: card This is the name of the generic UI component, not the React module! customization: css Design CSS customizability enhancement This is not a bug, nor a new feature

Comments

@RemyMachado
Copy link

RemyMachado commented Feb 7, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example: codesandbox

Steps:

  1. Use the ThemeProvider with the default theme
  2. Try to remove the MuiCardContent-root:last-child style (padding-bottom)
  3. It impacts the default MuiCardContent-root style (padding)

image

Current behavior 😯

Currently, when I try to remove the padding-bottom from MuiCardContent-root:last-child it impacts the padding of MuiCardContent-root. I can't find out a way to remove this css property without overriding the default padding value.

Expected behavior 🤔

We should be able to opt-out from a theme's css property, without impacting other css properties.

In this particular case I would expect the default padding to be kept intact:

.MuiCardContent-root {
    padding: 16px;
    padding-top: 16px;
    padding-right: 16px;
    padding-bottom: 16px; /* should be intact */
    padding-left: 16px;
}

Context 🔦

I'm trying to remove the padding-bottom: 24px from the CardContext component (&last-child).

The problem is that it impacts the default padding: 16px. When trying to unset the padding-bottom it removes the default padding.

Your environment 🌎

Latest.

@RemyMachado RemyMachado added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 7, 2023
@RemyMachado RemyMachado changed the title Removing a css property from the theme (override) Removing a css property from the theme (override) without setting another value Feb 7, 2023
@RemyMachado RemyMachado changed the title Removing a css property from the theme (override) without setting another value Removing a css property from the theme (override) without impacting another Feb 7, 2023
@zannager zannager added the customization: theme Centered around the theming features label Feb 8, 2023
@siriwatknp
Copy link
Member

The only way to have that experience is to adopt CSS variables to components (so that the value can fallback to the initial one) but it depends on the use case if it is worth adding them.

@siriwatknp siriwatknp added component: card This is the name of the generic UI component, not the React module! customization: css Design CSS customizability enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer customization: theme Centered around the theming features labels Feb 27, 2023
@RemyMachado
Copy link
Author

I'm currently using a custom CSS variables process (duplicating the theme to make it available in css modules stylesheets), but the initial value can't be erased. Do you have an example of what you are referring to? @siriwatknp

@eloiqs
Copy link

eloiqs commented Apr 27, 2023

I'm trying to achieve the exact same thing. Any idea why MuiCardContent has a different bottom padding when it's the last child?

@siriwatknp
Copy link
Member

siriwatknp commented Apr 28, 2023

@RemyMachado @eloiqs Here is one example:

Screen.Recording.2566-04-28.at.09.42.32.mov
// the component
const Div = styled('div')`
  --p: 1rem;
  --p-last: 1.5rem;
  padding: var(--p);
  &:last-child {
    padding-bottom: var(--pb-last, var(--p));
  }
`

By default, the last component's padding-bottom will be 1.5rem because of --p-last.

To ignore the --p-last and let it fallback to the --p, set the value of --pb-last to unset.

<Div sx={{ '--pb-last': 'unset' }}>

https://codepen.io/siriwatknp/pen/qBJjYXM

@RemyMachado
Copy link
Author

@siriwatknp I'm not sure I understand the relevance of your example, which doesn't use MUI. MuiCardContent-root:last-child doesn't have an editable CSS variable in the theme to achieve what you showed us...
This issue should be addressed using theme customization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: card This is the name of the generic UI component, not the React module! customization: css Design CSS customizability enhancement This is not a bug, nor a new feature
Projects
None yet
Development

No branches or pull requests

4 participants