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

[ExpansionPanel] Add useExpansionPanel hook #14616

Closed
wants to merge 6 commits into from

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Feb 21, 2019

Switching from cloneElement to Context. This is not ready. Just want to take material-size-bot for a ride.

@eps1lon eps1lon added new feature New feature or request component: accordion This is the name of the generic UI component, not the React module! labels Feb 21, 2019
@eps1lon eps1lon added this to the v4 milestone Feb 21, 2019
@eps1lon eps1lon force-pushed the feat/ExpansionPanel/context branch from 1326b5f to f14e12f Compare February 21, 2019 14:15
@mui-pr-bot
Copy link

This PR introduced some changes to the bundle size.

@material-ui/core: parsed: +0.05%, gzip: +0.19%

Details of bundle changes.

Comparing: f0cdca8...f14e12f

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core/Paper 0.00% 0.00% 83040 83040 21410 21410
@material-ui/core/Paper.esm 0.00% 0.00% 76728 76728 20462 20462
@material-ui/core +0.05%:small_red_triangle: +0.19%:small_red_triangle: 484797 485062 130083 130332
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 16235 16235 5159 5159
@material-ui/styles 0.00% 0.00% 63755 63755 18119 18119
@material-ui/system 0.00% 0.00% 15915 15915 3938 3938
colorManipulator 0.00% 0.00% 2290 2290 838 838
Button 0.00% 0.00% 212888 212888 61970 61970
Modal 0.00% 0.00% 211086 211086 61681 61681
@material-ui/core/Popper 0.00% 0.00% 146815 146815 46826 46826
@material-ui/core/useMediaQuery 0.00% 0.00% 9386 9386 3563 3563
docs.main 0.00% 0.00% 675841 675841 204947 204947
docs.landing 0.00% 0.00% 48963 48963 10275 10275
packages/material-ui/build/umd/material-ui.production.min.js +0.04%:small_red_triangle: +0.27%:small_red_triangle: 320431 320570 84703 84930

Generated by 🚫 dangerJS against f14e12f

@mbrookes
Copy link
Member

mbrookes commented Feb 21, 2019

Just want to take material-size-bot for a ride.

Should it be material-ui-size-bot (or just mui-size-bot to follow mu-bot naming)?

Looks great though!

warning(
false,
[
'Material-UI: You called onChange from a component that is not a child of a ',
Copy link
Member

Choose a reason for hiding this comment

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

We could revisit this convention

Suggested change
'Material-UI: You called onChange from a component that is not a child of a ',
'Material-UI: you called onChange from a component that is not a child of a ',

if (!this.isControlled) {
// not controlled, use internal state
this.state.expanded = props.defaultExpanded !== undefined ? props.defaultExpanded : false;
function useIsControlled(value) {
Copy link
Member

Choose a reason for hiding this comment

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

What's the value of this abstraction?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was me playing around a bit. I have a more generic abstraction locally that will deal with the controlled vs. uncontrolled value in general.

Though even in this primitive state it adds value: We can move possible discussions about what constitutes a "controlled" value into a single place (see #14092 (comment)). This would ensure a consistent controlled vs. uncontrolled API.

].join('\n'),
);

if (isMuiElement(child, ['ExpansionPanelSummary'])) {
Copy link
Member

Choose a reason for hiding this comment

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

How are you going to solve this problem? Though, I don't see the value of using the context if we still have to expose .muiName = 'ExpansionPanelSummary'.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was a bit premature with that statement. As soon as I looked at the code I realized we wouldn't gain as much as I initially thought.

What context would allow though is reaching into the ExpansionPanelSummary, grabbing the html ID, expose this in the context and then the content can get a aria-labelledby.

Context is definitely more powerful here. I need to finish up the implementation to fully understand what features this enables.

Copy link
Member

Choose a reason for hiding this comment

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

I'm happy that you are mentioning a11y. So far, we have had a hard time abstracting the accessibility label logic. It often requires the introducing of a global index structure or the usage of the context to propagate the changes down the tree. Our tradeoff so far has always been to defer the logic to the developers, saving, what we thought bundle size.

Copy link
Member Author

Choose a reason for hiding this comment

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

Context is currently my preferred solution to these problems. I like neither the SomePassedComponent prop + SomePassedComponentProps prop pattern nor cloneElement. It feels like black magic from the outside.

The Context + useSomeExposedPartFromTheContext custom hook pattern is way more predictable. While it might be more bundle size it resembles more what we're actually trying to achieve. The previous patterns only tried to emulate some context. Now we actually have some. Without the downsides of possibly defeating memoized components or props collision.

And with the new react-devtools debugging should be easier i.e. you actually see where the props are coming from.

@eps1lon eps1lon force-pushed the feat/ExpansionPanel/context branch from f14e12f to ab39b2f Compare February 26, 2019 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: accordion This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants