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

Dropdown: setState in onChange leads to mismatch of 'active' and 'selected' option #2243

Closed
jjjkkklll opened this issue Oct 23, 2017 · 8 comments · Fixed by #2252
Closed
Labels

Comments

@jjjkkklll
Copy link

jjjkkklll commented Oct 23, 2017

Steps

I want to setState() by onChange of the Dropdown

Expected Result

The state should be set and the dropdown should change its value.
The selected option should be active and selected

Actual Result

The state is set as expected
The selected option is set to active, the previously selected option is kept as selected.
=> Selected and active do not match the same option anymore

Version

0.75.1

Testcase

https://codesandbox.io/s/lrvqlpy7oz

@layershifter
Copy link
Member

You should use the Dropdown as controlled component, codesandbox.

@jjjkkklll
Copy link
Author

Thanks, but it seems like that does not help! Could you check my sandbox one more time, maybe I am doing something wrong?
https://codesandbox.io/s/nn2wn70r5j

@layershifter layershifter reopened this Oct 23, 2017
@layershifter layershifter changed the title Dropdown, setState in onChange leads to mismatch of 'active' and 'selected' option Dropdown: setState in onChange leads to mismatch of 'active' and 'selected' option Oct 23, 2017
@layershifter
Copy link
Member

Thanks, now I understand your problem, my poor display doesn't show issue to me 😭 Looks like problem with indexes, should be checked. Help is much appreciated.

@jjjkkklll
Copy link
Author

It looks like the issue is still present in some cases.

E.g. passing an element to the content of an option within name, text or content like so:

let options = [ { text: "1", value: "1", content: <span>a</span> }, ... ];

will lead to mismatch again.

ShowCase: https://codesandbox.io/s/pp0w7wrn7q

@oskarkook
Copy link

oskarkook commented Nov 5, 2017

Here's another one which is bugged: https://codesandbox.io/s/xr4xz2x9n4

In the first dropdown, select "3", then "1" and then open the second dropdown. You will see the mismatch.

@jjjkkklll
Copy link
Author

should I open a new issue for this?

@layershifter
Copy link
Member

Yes, please open a new issue and fully fill the issue template.

@akosidoctor26
Copy link

Do we have a fix for this issue?

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

Successfully merging a pull request may close this issue.

4 participants