-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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: when options contain custom elements, setState in onChange leads to mismatch of 'active' and 'selected' option #2296
Comments
Valid issue, help is much appreciated. |
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. |
There is a bug here, however, the examples are also using the Dropdown
|
@levithomason Thank you for the example, but now I do not understand how to get something like this: If the text has to be a string, I can't use text for it and content won't display it... Edit: regarding the element in the text tag. I took it from this post, which gave this example |
@jjjkkklll This is a longer standing issue that we'd love a PR for. We do not currently support an icon in the displayed active item, see #1147. I believe we changed the API since the links you've provided. You can still work around this by using the https://react.semantic-ui.com/modules/dropdown#dropdown-example-trigger |
Had a similar problem, fixed with trigger prop. Thanks @levithomason! <Form.Dropdown
trigger={<Label color={data.color}/>}
label="Color"
name="color"
onChange={this.onChange}
value={data.color}
selection
width={2}
compact
options={COLORS.map(color => ({
label: { color },
key: color,
value: color,
text: "",
}))}
/> |
This problem solved when opened dropdown It select automatically other index value :( ??!! |
There has been no activity in this thread for 90 days. While we care about every issue and we’d love to see this fixed, the core team’s time is limited so we have to focus our attention on the issues that are most pressing. Therefore, we will likely not be able to get to this one. However, PRs for this issue will of course be accepted and welcome! If there is no more activity in the next 90 days, this issue will be closed automatically for housekeeping. To prevent this, simply leave a reply here. Thanks! |
Any updates on this? The Dropdown component still seem to make all choices active (and bold) when choosing a single one. You can see this currently in action on the examples in the docs: https://react.semantic-ui.com/modules/dropdown#usage-trigger-image If you trigger the dropdown by clicking on the avatar, and then choose an option - the next time you trigger the dropdown: all the options are set to active. Also not to nitpick, but I can see an inverted triangle for the pointer below where it's rendered as seen here: https://i.imgur.com/iqcV7gk.png (note: this only occurs before you select an active choice). Any help would be much appreciated on this. Thank you! |
I believe I've run into yet another variation of this issue (mismatch of "selected" and "active" attributes) that appears in even much simpler scenarios, i.e. not involving avatars or other non-text components in the options. Steps
Expected result "Charlie" should be both active and selected. Actual result "Charlie" is active (correct), but "Alpha" is selected (not correct). This is a problem, because, when you open and then again blur the dropdown (without making an intentional change to the selection), it will still switch to to the selected one. This seems to happen after any modification of the options after the initial creation of the dropdown, e.g. initialising with non-empty (but different) options doesn't help. Version 0.82.2 Showcase |
Hey @hsch, try triggering another render() by changing your componentDidMount() method, by calling this.setState() one more time to set the active value of your dropdown (as you probably know, each setState() triggers render()...for more information, read for example here: https://reactjs.org/docs/react-component.html#componentdidmount):
Here is your adapted code example, which seems to be working for me: |
This works |
This works for me, but is this just because
This should check the new |
There has been no activity in this thread for 180 days. While we care about every issue and we’d love to see this fixed, the core team’s time is limited so we have to focus our attention on the issues that are most pressing. Therefore, we will likely not be able to get to this one. However, PRs for this issue will of course be accepted and welcome! If there is no more activity in the next 180 days, this issue will be closed automatically for housekeeping. To prevent this, simply leave a reply here. Thanks! |
Steps
I want to setState() within onChange of the Dropdown and have custom elements within the options like so:
Expected Result
The selected option should be active and selected
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
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
The content does not appear in the dropdown
If
text
is used instead ofcontent
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
The content does appear in the dropdown
Questions:
What should I use,
text
orcontent
for this case?How to solve the mismatch?
Version
0.76.0
Showcase
https://codesandbox.io/s/pp0w7wrn7q
Partially solved here:
#2252
The text was updated successfully, but these errors were encountered: