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

[Select] Fix classes merge issue #11904

Merged
merged 2 commits into from
Jun 19, 2018
Merged

[Select] Fix classes merge issue #11904

merged 2 commits into from
Jun 19, 2018

Conversation

C-Rodg
Copy link
Contributor

@C-Rodg C-Rodg commented Jun 18, 2018

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

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 18, 2018

@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 oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI component: select This is the name of the generic UI component, not the React module! labels Jun 18, 2018
@C-Rodg
Copy link
Contributor Author

C-Rodg commented Jun 18, 2018

@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.

@oliviertassinari
Copy link
Member

@C-Rodg This is the merge classes logic I was referring to and that we could put into a module and use:
https://github.com/mui-org/material-ui/blob/ad4df1c16a9070582250db941dd97854215bc31f/packages/material-ui/src/styles/withStyles.js#L168-L202

@oliviertassinari oliviertassinari self-assigned this Jun 19, 2018
@oliviertassinari
Copy link
Member

@C-Rodg I'm continuing this pull-request.

@oliviertassinari oliviertassinari changed the title [Select] Add children and classes to inputProps [Select] Fix classes merge issue Jun 19, 2018
@oliviertassinari oliviertassinari merged commit 30ede7c into mui:master Jun 19, 2018
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Jun 19, 2018
acroyear pushed a commit to acroyear/material-ui that referenced this pull request Jul 14, 2018
* 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]}.`,

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...

Copy link
Member

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?

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.

Copy link
Member

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.

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.

Copy link
Member

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?

Copy link

@nicosommi nicosommi Aug 15, 2018

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.

Copy link
Member

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.

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)

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: select This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants