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
206 stars 95 forks source link

Does it have a way to clear the selection? #55

Open myt-sheila opened 1 year ago

josephhelou commented 1 year ago

Any updates on this issue ?

danish1658 commented 1 year ago

@josephhelou v 2.0.5 coming this Sunday , With Awesome improvements and Clear Function onDemand.

josephhelou commented 1 year ago

@danish1658 any updates regarding the release ?

danish1658 commented 1 year ago

Will be available tomorrow, will update you soon after the version patch

SGamrekelashvili commented 1 year ago

When will we get the update?

AlekoG commented 1 year ago

Hey, it's over 2 weeks after you say "will be available tomorrow", any news?

myt-sheila commented 1 year ago

@danish1658, any updates? 🙏

danish1658 commented 1 year ago

Im sorry for the delay, i will be committing the changes anytime this weekend.

myt-sheila commented 1 year ago

Hello, @danish1658, any updates? 🙏

stefan1230 commented 1 year ago

Any updates on the clear option?

vtxmg commented 1 year ago

any updates on the clear option?????

WangShayne commented 1 year ago

any update with clear selected? thx

============================================ update
simple but useful :XD

SelectList.tsx

import React, { useImperativeHandle,forwardRef  } from 'react';
...
const SelectList: React.FC<SelectListProps> =  forwardRef((props,ref) => {
    ...
    useImperativeHandle(ref, () => {
        return {
            resetData: resetData,
        };
    });

    const resetData = () => {
        setSelectedVal("")
        setSelected("")
    }
    ...
})

Use.tsx

const SelectRef = useRef(null);
...
 <SelectList data={option} save="key" ref={SelectRef} />
...
const cleanFuc = () => { SelectRef.current && SelectRef.current.resetData}
hassancodess commented 1 year ago

Here's a simple and straightforward way to clear the states of SelectList or MultiSelectList

In your component file

  1. Create a state and initialized it by 0.

    const [reset, setReset] = useState(0);
  2. Create a function named clearStates that will handle the state reset.

    const clearStates = () => {
    setReset(reset + 1)
    };
  3. Use the key prop of the MultipleSelectList component and set it to the reset state. This will trigger the component to unmount and remount when changed.

    <MultipleSelectList
    key={reset}
    placeholder="Select People"
    searchPlaceholder="Search People..."
    setSelected={val => setSelectedPeople(val)}
    data={people}
    save="name"
    label="Persons"
    />
  4. Create a button with an onPress that triggers the clearStates function.

    <Button mode="contained" onPress={clearStates}>
    Clear States
    </Button>
faisalaltell12 commented 1 year ago

Thank you @hassancodess. This is a very user friendly method that works perfectly!

srijit-ops commented 1 year ago

@danish1658 any updates regarding the clear function? Still can't find any solution to clear the selection in your npm package.

jaimeevelt01 commented 1 year ago

Will this update the data when selected? Is this fix released yet?

AshrazRashid commented 8 months ago

@jaimeevelt01 https://github.com/AshrazRashid/react-native-dropdown-select-list.git