-
Notifications
You must be signed in to change notification settings - Fork 833
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
Add closeOnSelect prop to SelectMenu #588
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.
Thank you for your contribution!
Overall it looks like it is in the right path. I've made two comments. One of them is minor and refers to formatting. The other is a question to Matt in terms of the behavior (please also jump in if you want!).
@@ -38,7 +38,9 @@ export default class OptionsList extends PureComponent { | |||
/** | |||
* This holds the values of the options | |||
*/ | |||
selected: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | |||
selected: PropTypes.arrayOf( |
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.
Did you configure your editor? I don't think these lines should be formatted.
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'm using VS Code. It's picking up the prettier settings in the package.json
and as there is no printWidth
setting is going with the default of 80. This line is longer than that, which is why it is being formatted.
I've left it as is as the prettier settings would need to explicitly state a larger printWidth
. Is this ok? Would you rather I change it back?
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.
Weird. Maybe nobody had touched the file in a while. Thanks for checking!
@@ -201,6 +204,9 @@ export default class OptionsList extends PureComponent { | |||
|
|||
handleSelect = item => { | |||
this.props.onSelect(item) | |||
if (!this.props.isMultiSelect && this.props.closeOnSelect) { |
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 realized that hitting the Enter
key has a similar behavior (closing the menu). It makes me wonder if we should also have the check for multiSelect
and closeOnSelect
in the handleEnter
method (you can always close the menu by hitting ESC
in that case). Doing this would be a change of contract in the interface. I'm not sure if we want to do that now.
@mshwery - would love some thoughts!
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 we could save that for a separate PR if the current behavior is problematic. I think it's fine to leave alone for now TBH, though I agree with your idea!
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.
LGTM! Nice work
src/select-menu/src/OptionsList.js
Outdated
@@ -48,7 +50,8 @@ export default class OptionsList extends PureComponent { | |||
filterPlaceholder: PropTypes.string, | |||
filterIcon: PropTypes.string, | |||
optionsFilter: PropTypes.func, | |||
defaultSearchValue: PropTypes.string | |||
defaultSearchValue: PropTypes.string, | |||
closeOnSelect: PropTypes.bool |
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.
While the name is pretty semantic would you mind adding some jsdoc description above the new 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.
no worries, done
@@ -201,6 +204,9 @@ export default class OptionsList extends PureComponent { | |||
|
|||
handleSelect = item => { | |||
this.props.onSelect(item) | |||
if (!this.props.isMultiSelect && this.props.closeOnSelect) { |
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 we could save that for a separate PR if the current behavior is problematic. I think it's fine to leave alone for now TBH, though I agree with your idea!
This change adds a prop that when true the select menu will close when an option has been selected. closes segmentio#456
312b0f9
to
68f820a
Compare
Thanks @solon-aguiar @mshwery! I've updated my PR & commit message, and added a note to the docs also. |
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.
Thanks!
🎉 👍
No worries, welcome 🎆 |
We need to pull out `closeOnSelect` so that we don't pass it in `props` to the `Pane` in `OptionsList`. Follow on to: #588 | Before | After | | --- | --- | | ![image](https://user-images.githubusercontent.com/2907397/63835739-ef2da200-c92c-11e9-97ce-5d0e8b865c54.png) | ![image](https://user-images.githubusercontent.com/2907397/63835743-f5238300-c92c-11e9-87d5-1a232c02c040.png) |
This is a rough WIP to check this is the right approach, or if there is a better way.In response to #456 this change adds a prop to
SelectMenu
to enable closing the select menu when an option is selected.