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

feat(Dropdown): add closeOnChange prop #1244

Closed
apiv opened this issue Jan 28, 2017 · 7 comments
Closed

feat(Dropdown): add closeOnChange prop #1244

apiv opened this issue Jan 28, 2017 · 7 comments

Comments

@apiv
Copy link
Contributor

apiv commented Jan 28, 2017

Steps

  1. With a single-selection dropdown, select an item. The menu closes on select.
    single
  2. With a multi-selection dropdown, the menu always stays open.
    multi

Proposed changes

There are use cases for both menu open/close behaviors, but in some cases, I may want to close the dropdown on select. I'm proposing that we add a closeOnChange or closeOnSelect option to Dropdown, defaulting to true for single selects and false for multi-selects.

Version

v0.64.4

Testcase

http://react.semantic-ui.com/modules/dropdown#search-selection
http://react.semantic-ui.com/modules/dropdown#multiple-search-selection

I'm willing to submit a PR for this if we decide this option is worth adding to Dropdown.

@apiv apiv changed the title Dropdown should take option {boolean} closeOnSelect, for multiple-select dropdowns feat(Dropdown): add closeOnSelect prop Jan 28, 2017
@levithomason
Copy link
Member

I'm all for this change. Let's go with closeOnChange.

I'd think this would only close on changes invoked by user interaction, such as, click and enter. This way programmatic updates don't usurp user control. Thoughts?

@apiv
Copy link
Contributor Author

apiv commented Jan 30, 2017

I think that fits the pattern, since changing value does not trigger onChange, only user interaction does. I'll submit a pull request shortly.

@apiv apiv changed the title feat(Dropdown): add closeOnSelect prop feat(Dropdown): add closeOnChange prop Jan 30, 2017
@levithomason
Copy link
Member

@apiv Heads up, if the PR description contained fixes #1244 it would auto close the issue. However, the string must be one of the supported string values. The actual PR included fulfills issue #1244 so the issue remained open after merge.

Fixed in #1244, thanks for the work!

@andrewleith
Copy link

I'm having some trouble with this. When I use a dropdown without closeOnChange, it automatically closes when I select an option, which is exactly what I want. When I add the simple prop to the dropdown (because I would like this menu to open on hover), it no longer closes when I select an option. Why would the simple prop even affect this behavior at all?

Adding closeOnChange kind of works: it closes the dropdown, but only after I make a second selection.

Any advice?

@levithomason
Copy link
Member

Per the docs, the opening and closing are done via CSS:

simple {bool} A simple dropdown can open without Javascript.

My guess is that you are probably getting some kind of conflicting behavior by having CSS and JS attempt to control the open state. I would instead move to a controlled component pattern and toggle the open prop on onMouseEnter and onMouseLeave.

If you post a codepen showing your issue, perhaps someone will give more details.

@andrewleith
Copy link

Here is a pen showing the issue:
https://codepen.io/andrewleith/full/WEwpRb

The first menu uses the simple prop, and it takes 2 clicks to have the menu close upon selection. The second menu closes fine on the first click (after opening the sub-menu by clicking it).

I'm just going to get rid of the simple prop in my case :)

@levithomason
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants