Semantic-Org/Semantic-UI-React

Dropdown: when options contain custom elements, setState in onChange leads to mismatch of 'active' and 'selected' option

Open

#2296 opened on Nov 6, 2017

View on GitHub
 (14 comments) (2 reactions) (0 assignees)JavaScript (13,136 stars) (4,065 forks)batch import
bughelp wantedstale

Description

Steps

I want to setState() within onChange of the Dropdown and have custom elements within the options like so:

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

Expected Result

  1. The selected option should be active and selected

  2. The state should be set and the dropdown should change its value. The content of the option <span>a</span> should appear in the dropdown.

Actual Result

  1. 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

  2. The content does not appear in the dropdown

If text is used instead of content

  1. 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

  2. The content does appear in the dropdown

Questions: What should I use, text or content for this case? How to solve the mismatch?

Version

0.76.0

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

Partially solved here: https://github.com/Semantic-Org/Semantic-UI-React/pull/2252

Contributor guide