danish1658 / react-native-dropdown-select-list

☝️ React Native Select List Equivalent to Html's Select with options"
https://www.npmjs.com/package/react-native-dropdown-select-list
MIT License
200 stars 89 forks source link

Do we have the option to delete the selection somehow? #51

Open ToppantoB opened 1 year ago

ToppantoB commented 1 year ago

Resetting the "selected" to an empty string doesn't do the trick. Maybe I missed something.

danish1658 commented 1 year ago

setSelected ('')

ToppantoB commented 1 year ago

That set's the selected's value back to "empty", but the dropdown will still display the last selected element. It will not go back to the original placeholder text.

danish1658 commented 1 year ago

No it will show the placeholder text

ToppantoB commented 1 year ago

This is my code snippet, am I messing something up here?

const [selected, setSelected] = useState("");
...
const saveWork = () => {
        saveWork();
        setSelected('');
   };
...
<View style={styles.container}>
   ...
   <SelectList
      boxStyles={styles.dropDown}
      dropdownStyles={styles.dropDown}
      setSelected={(val: string) => setSelected(val)}
      data={dropdownData}
      save="key"
   />
   ...
</View>

Calling the saveWork calls the setSelected('') , but the dropdown is not reset to the placeholder text. (see the gif I attached)

Animation

Also, how should the component even know that the selected was reset? We never pass the value of the selected variable to it.

danish1658 commented 1 year ago

I will reply you with an expo snack shortly

DavidPurcell1973 commented 1 year ago

I will reply you with an expo snack shortly

I having the same issue did this get resolved?

ToppantoB commented 1 year ago

Not yet, I'm still waiting for the expo snack from @danish1658

akruz97 commented 1 year ago

Todavía no, sigo esperando la merienda de la expo de@danish1658

Estaba en lo mismo y lo solucione, estableciendo un objeto para defaultOption ` const DEFAULT_OPT = { key: 0, value: 'Seleccione una opción'} const [defaultOption, setDefaultOption ] = useState(DEFAULT_OPT);

const saveWork = () => { saveWork(); setSelected(''); setDefaultOption(DEFAULT_OPT); };

<SelectList defaultOption={defaultOption} boxStyles={styles.dropDown} dropdownStyles={styles.dropDown} setSelected={(val: string) => setSelected(val)} data={dropdownData} save="key" /> `

debapriy0 commented 1 year ago

I tried to modify a few lines, see if this helps you

and you can use this resetSelectedData, setSelectedData two functions with ref.

faisalaltell12 commented 1 year ago

How is this done with MultipleSelectList? I basically want to reset all selected items. I set the state to an empty array. It still displays in the UX some selected items.

ITyukz11 commented 2 months ago

any update?