react-native-dropdown-select-list icon indicating copy to clipboard operation
react-native-dropdown-select-list copied to clipboard

Do we have the option to delete the selection somehow?

Open ToppantoB opened this issue 2 years ago • 11 comments

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

ToppantoB avatar Jan 08 '23 19:01 ToppantoB

setSelected ('')

danish1658 avatar Jan 09 '23 13:01 danish1658

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.

ToppantoB avatar Jan 09 '23 13:01 ToppantoB

No it will show the placeholder text

danish1658 avatar Jan 09 '23 18:01 danish1658

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.

ToppantoB avatar Jan 12 '23 07:01 ToppantoB

I will reply you with an expo snack shortly

danish1658 avatar Jan 12 '23 10:01 danish1658

I will reply you with an expo snack shortly

I having the same issue did this get resolved?

DavidPurcell1973 avatar Jan 20 '23 04:01 DavidPurcell1973

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

ToppantoB avatar Jan 20 '23 08:01 ToppantoB

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" /> `

akruz97 avatar Feb 21 '23 22:02 akruz97

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

  • change 1 const MultipleSelectList: React.FC<MultipleSelectListProps> = React.forwardRef((props,ref) => {
  • change 2 React.useImperativeHandle(ref,()=>({ resetSelectedData, setSelectedData })) const resetSelectedData = () => { setSelectedVal("") setFilteredData(data) _setFirstRender(false); } const setSelectedData = (val) => { let selectedValue = data?.filter((item:any)=>{ if(val?.includes(item.key)){ return {value: item.value} } }).map((item:any)=>{return item.value}) setSelectedVal(selectedValue) } ...rest of the code })

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

debapriy0 avatar Apr 20 '23 18:04 debapriy0

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.

faisalaltell12 avatar Jun 17 '23 12:06 faisalaltell12

any update?

ITyukz11 avatar Jun 19 '24 08:06 ITyukz11