Semantic-UI-React icon indicating copy to clipboard operation
Semantic-UI-React copied to clipboard

Dropdown Component Remote Options Filtering Bug

Open mustafa519 opened this issue 6 years ago • 11 comments

Bug Report

Steps

I was trying to create tag selector component with Semantic UI Dropdown's multiple remote options. When second API call changes the options, then the old selected items, hiding suddenly. It only seems same keyword API call. And i think it might be filter function related bug.

Also i've provided codesandbox example below.

Expected Result

Selected items should keep as user selected for all API calls. Doesn't need to hide selected items according to options. Already options are filtering for already selected items. Also my problem is totally same with at #3254 issue.

Actual Result

Selected items are hiding/filtering according to options even they keep in value of the Dropdown component.

Version

0.88.2

Testcase

https://codesandbox.io/s/semantic-ui-react-z4qy1

mustafa519 avatar Jun 09 '20 14:06 mustafa519

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

welcome[bot] avatar Jun 09 '20 14:06 welcome[bot]

I can confirm this behaviour. The problem is that the already selected items are still saved in the dropdown component but the component does not render those values as "labels" if the options which are coming from a fetch change suddenly.

Out of this behaviour I conclude that the Dropdown component somehow renders its "labels" by pulling the value out of the options object. In this case this object is rewritten on every new fetch which means that the previously selected values vanish from the UI.

hxeo avatar Jul 30 '20 22:07 hxeo

@layershifter I can confirm also the above bug. As long as the selected values are not present to the current options object, then the selected labels are disappearing. Would this be something that you plan to fix soon?

zzacharo avatar Dec 02 '20 12:12 zzacharo

I'm facing exactly the same issue. It would be really great to have a fix for this as quick as possible

audrium avatar Dec 02 '20 12:12 audrium

Can confirm this issue is still happening - is there a plan to fix?

cristisp avatar Jun 25 '21 08:06 cristisp

@mustafa519 in your test case, the options prop is changing when you search. Essentially, you are removing options available to the component to display when doing this. The values that are set to display on the component need to be present in options. The Dropdown component itself does the filtering. The options still all must be present.

If you are getting options from somewhere remote on an API, you will technically need to add every selected value as an object to the options array in order for it to show up.

brianespinosa avatar Jul 12 '21 20:07 brianespinosa

@mustafa519 @brianespinosa do you have a solution for this issue ?

abdoulub avatar Sep 30 '21 13:09 abdoulub

@abdoulub I recommend going to Stack Overflow and asking a question sharing your code and showing what you have tried there.

This bug report shows the selectable options switching between two different lists of options. The dropdown is behaving as expected. My comment above states what the issue is relative to this example. The component does not know that the available options are switching.

brianespinosa avatar Sep 30 '21 21:09 brianespinosa

Thanks @brianespinosa for your quick answer, I already asked a question in StackOverflow about this with my code https://stackoverflow.com/questions/69388297/react-semantic-ui-dropdown-remote-fetch/69388342

thank you

abdoulub avatar Oct 01 '21 07:10 abdoulub

@brianespinosa I think that the expected behaviour is perceived as a bug from the users of the Dropdown component. Is there any plan to decouple the stored options from the values displayed?

zzacharo avatar Oct 01 '21 07:10 zzacharo

@zzacharo I am not sure what you mean by decouple stored values from what values are displayed in the context of this example. The Dropdown component in the above example is getting the options passed to it switched to a different array of options. The dropdown should not be greedily keeping all values it has ever been provided in order to show the values if a developer sets a value then changes the possible options. That is far beyond the scope of how a dropdown component would work.

This solution is 100% workable by having a comprehensive list of options available for selection that do not change from outside of the component.

brianespinosa avatar Oct 04 '21 22:10 brianespinosa