Semantic-Org/Semantic-UI-React

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

Open

#2,296 建立於 2017年11月6日

在 GitHub 查看
 (14 留言) (2 反應) (0 負責人)JavaScript (13,136 star) (4,065 fork)batch import
bughelp wantedstale

描述

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

貢獻者指南