-
-
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
[Select] Fix classes merge issue #11904
Conversation
@C-Rodg I don't understand, this logic was removed in #11873. It's repetitive logic. Regarding solving #11867. I think that we should be extracting the classes merge utils out from the withStyles.js module and use it in the Select.js module. We would also need to add a unit test to make sure the logic is correct. |
@oliviertassinari Ahhh, sorry, I must've misunderstood the issue. I'm not very familiar with the withStyles module or styling MUI in-general so I may not be the best person to take this on, but if you want to provide a little more guidance I'd be more than happy to make an attempt at least. |
@C-Rodg This is the merge classes logic I was referring to and that we could put into a module and use: |
@C-Rodg I'm continuing this pull-request. |
* Add children and classes to input props for Select component * [Select] Fix classes merge issue
[ | ||
`Material-UI: the key \`${key}\` ` + | ||
`provided to the classes property is not valid for ${getDisplayName(Component)}.`, | ||
`You need to provide a non empty string instead of: ${newClasses[key]}.`, |
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.
@oliviertassinari Sorry to bother you here but I think this may be an issue...
I see the condition || typeof newClasses[key] === 'string'
on line 24 and then this message: ...You need to provide a non empty string instead of...
I'm confused... is this right? I'm getting this warning but it works (the class is applied... newClasses[key]
is a non empty string).
root
provided to the classes property is not valid for ListItem.
You need to provide a non empty string instead of: css-month-items-i14xvf
That's the message I get
Should this ||
be a &&
? Or should the message be slightly different? Or... I'm completely wrong, of course...
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.
@nicosommi Do you have a reproduction example?
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.
@oliviertassinari I found what is happening. As I suspected, it is not an issue with MUI :)
I was passing what the glamor css
function returns (implementing my own override instead of using withStyles
HOC), which is not a string but an object with a toString
method on it. So it goes wrong through this validation, but when converted to string, it works. I solved by using toString()
when passing it to MUI. So now no warning, and it works!
Sorry for the delayed response, I was digging into it and I just found the real cause. It may help for future reference if someone is trying to take a similar approach.
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.
It's good to now. I guess it's better to be explicit about it. I have seen too many people try crazy stuff with this API.
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.
👍
In my case I'm trying to avoid using the HOC mainly because it is not friendly with the new React Context API (correct me if I'm wrong), and thus I created a standard function that process the style objects when I call it and pass the theme with a custom provider I created using this new context API with the render prop.
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.
it is not friendly with the new React Context API
What does it mean?
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.
What does it mean?
That it is using this instead of this
In practical terms the new context is used in a declarative way by rendering a consumer and using the children on the default render prop.
So my component wrapper looks like this:
<ThemeProvider.Consumer>
{theme => (
<List classes={processStyleObjects(styles, theme)}>
{this.props.children}
</List>
)}
</ThemeProvider.Consumer>
Instead of creating the HOC based on the legacy context API.
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.
It's an implementation detail. It doesn't matter to end users. You can very well using recompose toRenderProps helper with withTheme HOC. Or use the 11 lines render prop wrapper we document for withStyles.
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.
Indeed, it is.
You can very well using recompose toRenderProps helper with withTheme HOC
😲 Thank you for the tip! I didn't know about that helper
Or use the 11 lines render prop wrapper we document for withStyles
Do you have a link? I can't find that example (I'm reading here)
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,
I have added children and classes to the inputProps for the Select component, which prevents the removal of default styling mentioned in #11867.
Thanks!
Closes #11867