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

Add closeOnSelect prop to SelectMenu #588

Merged
merged 2 commits into from
Jun 20, 2019

Conversation

robphoenix
Copy link
Contributor

@robphoenix robphoenix commented Jun 19, 2019

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.

Copy link
Contributor

@solon-aguiar solon-aguiar left a 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(
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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) {
Copy link
Contributor

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!

Copy link
Contributor

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!

Copy link
Contributor

@mshwery mshwery left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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
@robphoenix
Copy link
Contributor Author

Thanks @solon-aguiar @mshwery!

I've updated my PR & commit message, and added a note to the docs also.
I've left the formatting change for now, as it is complying with the prettier settings, lmk if you want me to change it. 👍

@robphoenix robphoenix changed the title WIP: close select menu on select Add closeOnSelect prop to SelectMenu Jun 20, 2019
Copy link
Contributor

@solon-aguiar solon-aguiar left a comment

Choose a reason for hiding this comment

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

Thanks!

🎉 👍

@robphoenix
Copy link
Contributor Author

No worries, welcome 🎆

@solon-aguiar solon-aguiar merged commit a3b44d1 into segmentio:master Jun 20, 2019
colinking added a commit that referenced this pull request Aug 28, 2019
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) |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants