-
-
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
makeStyles: Styles are not being overridden if the original style is declared with a function #26823
Comments
I've updated the codesandbox to use v5 - https://codesandbox.io/s/material-demo-forked-phnu0?file=/demo.tsx I can reproduce the issue. Not sure what would be the timeline for us to debug the issue. My suggestion in the mean time would be to use the |
Hi @mnajdova, thanks for the update! We currently don't "augment" the Material UI theme object, we use two different objects to deal with our Styled System and Material UI components. So we'll probably have to 'merge' them to make our lives easier.
Could you point me what are those performance implications? We have noted some of them, but it would be nice to have some more information about it - including how to avoid them. |
@danguilherme sure these could be a good starting points - #21657, #21143 Note that, these are fixed by v5 and the new @material-ui/styled-engine (fixed in terms of there will be better performance if the alternatives are used) The general problems with Also, this may be relevant - #26571 |
This is a legacy package. We no longer spend time fixing it. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @danguilherme How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Properties declared with functions in
makeStyles
(e.g.backgroundColor: props => props.color
) are not overridden by latest styles that override the same property, but without a function. For example, for this style hook:A component using both classes (e.g.
className={`${classes.root} ${classes.redBackground}`}
) will always have a background color as "props.color
" (see the example code sandbox in the "Steps to Reproduce" section).Current Behavior 😯
Given the following
useStyles
declaration:Rendering the following component
Renders two
Avatar
components with a green background:Expected Behavior 🤔
The first Avatar has a green background, and the second has a transparent background.
Steps to Reproduce 🕹
Running example: https://codesandbox.io/s/nice-nobel-cwg7t (using Material UI v4 because
makeStyles
seems to be broken in the latest beta of v5).Changing the following line, it works as expected.
Or, if you're feeling like doing something more hacky, this also works:
Context 🔦
I am building an Avatar component for our design system, wrapping the Material UI's
Avatar
.It has 3 different sizes and two variants:
default
, with a dark background, andoutline
, with no background.I am using different class names in the
makeStyles
declaration to avoid the excessive use of ternaries, and neatly group variants' styles. So in the component I can do something like this:Here is how it looks like so far, simplified.
I am aware I can just move the
backgroundColor
declaration to thedefault
variant -- that's how I am going to fix my issue.But I still believe the mentioned behaviour is not working as expected - or it is just not documented.
Your Environment 🌎
`npx @material-ui/envinfo`
Browser used: Chrome
The text was updated successfully, but these errors were encountered: