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

[IconMenu] Add missing default iconStyle #3514

Merged
merged 1 commit into from
Mar 1, 2016

Conversation

pdf
Copy link
Contributor

@pdf pdf commented Feb 28, 2016

Otherwise IconButton explodes due to undefined iconStyle

@@ -158,6 +158,7 @@ const IconMenu = React.createClass({
},
touchTapCloseDelay: 200,
useLayerForClickAway: false,
iconStyle: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @pdf! If we move forward with this, could you put this in the object in alphabetical order?

@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

@oliviertassinari @alitaheri This seems like it's an issue since we moved to Object.assign. The iconStyle prop could be undefined and you can't call Object.assign with undefined as the first argument. I'm not sure if we should set it as a defaultProp or if there is a better alternative.

@pdf
Copy link
Contributor Author

pdf commented Feb 28, 2016

Yeah, this does feel to me like a band-aid, rather than a fix for the root cause.

An alternative is to always use Object.assign({}, ...)

Probably worth noting that IconButton will also explode if you pass it a null iconStyle.

@pdf pdf force-pushed the icon-menu-missing-default-iconStyle branch from 0776efa to 7fe7d47 Compare February 28, 2016 04:38
@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

An alternative is to always use Object.assign({}, ...)

I agree that's the pattern we've been used in the past for other components for style props that may be undefined. I haven't fully considered the implications of the defaultProp approach vs adding an empty object in the Object.assign call.

The previous mergeStyles method that this replaced always used an empty Object to merge styles into.

@mbrookes
Copy link
Member

An empty object in mergeStyles may be preferable, otherwise the default in the docs will show as {}.

@mbrookes mbrookes changed the title Add missing default iconStyle to IconMenu [IconMenu] Add missing default iconStyle Feb 28, 2016
@alitaheri
Copy link
Member

Also note that all styles that are coming from props MUST not be touched, otherwise, reused instances will be mutated and hard-to-track bugs will infest the code! so, everywhere using props, we must do Object.assign({}, ...).

@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

I agree.

Thanks for raising this @pdf! Could you make that change defaultProp -> Object.assign({}, ...)?

@mbrookes mbrookes added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Feb 29, 2016
@pdf
Copy link
Contributor Author

pdf commented Feb 29, 2016

Give me a day or two @newoga - I want to take a closer look at this, pretty sure the issue is more wide-spread.

@pdf pdf force-pushed the icon-menu-missing-default-iconStyle branch from 7fe7d47 to df903b4 Compare March 1, 2016 10:29
@pdf
Copy link
Contributor Author

pdf commented Mar 1, 2016

I think I checked all the other usage of Object.assign, and this appears to be the only particularly dangerous usage.

@nathanmarks nathanmarks added PR: Review Accepted 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 Mar 1, 2016
@nathanmarks
Copy link
Member

@newoga Change looks good 👍

mbrookes added a commit that referenced this pull request Mar 1, 2016
@mbrookes mbrookes merged commit f312f07 into mui:master Mar 1, 2016
mbradleyis pushed a commit to staticinstance/material-ui that referenced this pull request Mar 7, 2016
@zannager zannager added component: Icon The React component. component: menu This is the name of the generic UI component, not the React module! labels Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Icon The React component. component: menu 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.

6 participants