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 popover width and add autoWidth prop #8307
[Select] Fix popover width and add autoWidth prop #8307
Conversation
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 would be good to have a test and a demo for this new feature.
@@ -343,6 +349,14 @@ class SelectInput extends React.Component<AllProps, State> { | |||
...MenuProps.MenuListProps, |
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.
I think that this logic is broken.
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.
I didn't even touch this line. It seems reasonable to me. 👍
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.
I have the feeling that if a user provides a MenuListProps
property in MenuProps
, the merge won't happen correctly.
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.
I think it will merge correctly, but I'll verify the logic.
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.
My bad.
@@ -343,6 +349,14 @@ class SelectInput extends React.Component<AllProps, State> { | |||
...MenuProps.MenuListProps, | |||
role: 'listbox', | |||
}} | |||
PaperProps={{ | |||
...MenuProps.PaperProps, |
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.
I think that this logic is broken.
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.
Why?
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.
My bad.
src/Select/SelectInput.js
Outdated
...MenuProps.PaperProps, | ||
style: { | ||
minWidth: | ||
this.state.anchorEl != null && !autoWidth ? this.state.anchorEl.clientWidth : 0, |
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.
We might don't want to inline the logic given it start to be complexe.
@oliviertassinari Indeed, but I don't know how to test the width of the component. Is this even possible without actually rendering the component in a browser? |
@leMaik I think that testing this in the browser will be hard to assert, the width might change from one browser to another. So for the sack of effectiveness, I would stick to a jsdom test. Yes, you can define your own width to the element with jsdom :). |
@oliviertassinari Thanks, I'll look into that tonight and add tests. |
@leMaik I'm gonna continue this PR if needed. Hold on. |
@oliviertassinari Well, I was going to continue this this weekend (today) but fine, feel free to get this done. 👍 |
@oliviertassinari I didn't find any way to get an element's width using JSDOM. It doesn't seem to have a layout algorithm so the widths are always zero. 😕 |
@leMaik I will have a look at it |
@oliviertassinari Thank you, I'm curious how that will work. 👍 I just added a demo and removed the inline minWidth calculation. Edit: It would be awesome if the linter could be added as a pre-commit hook. 🙄 |
72f9e73
to
5ac72b2
Compare
multiple: boolean, | ||
MenuProps?: Object, | ||
name?: string, | ||
autoWidth: boolean; |
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.
Shouldn't autoWidth
be optional?
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 optional yes.
src/Select/SelectInput.js
Outdated
@@ -14,7 +14,7 @@ export type Props = { | |||
* If true, the width of the popover will automatically be set according to the items inside the | |||
* menu, otherwise it will be at least the width of the select input. | |||
*/ | |||
autoWidth?: boolean, | |||
autoWidth: boolean, |
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.
See above.
@leMaik Thanks |
@oliviertassinari Nice! 🎉 |
This sets the minimum width of a Select's popover to the width of the select field and adds an
autoWidth
prop to disable this, similar to v0.x of material-ui.Closes #8286