fateh999 / react-native-paper-dropdown

Dropdown using react native paper TextInput and Menu
MIT License
130 stars 74 forks source link

Solution for clearing selected item in dropdown. #40

Closed DrPolymath closed 1 month ago

DrPolymath commented 2 years ago

Hello, I really need help in this matter. In my project, I have created 2 dropdown. The option list of the second dropdown is based on what user selected in the first dropdown. So supposedly, the selected item in the second dropdown should be cleared every time the selected item in the first dropdown change. How should I do that? I have tried this approach but it doesnt work.

const [showDropDown1, setShowDropDown1] = useState(false); const [showDropDown2, setShowDropDown2] = useState(false);

const [rI, setrI] = useState('')
const [lI, setlI] = useState('')

const remoteItems = [
    {id: 1, label: 'Item 1', value: 'item-1'},
    {id: 2, label: 'Item 2', value: 'item-2'},
];
const lItems = [
    {id: 1, label: 'L 1', value: 'l-1'},
    {id: 2, label: 'L 2', value: 'l-2'},
];

const handleSetrI = (rI) => {
    setlI('')
    setrI(rI);
}

return (

setShowDropDown1(true)} onDismiss={() => setShowDropDown1(false)} value={rI} setValue={(val) => handleSetrI(val)} list={remoteItems} /> setShowDropDown2(true)} onDismiss={() => setShowDropDown2(false)} value={lI} setValue={setlI} list={lItems} />
)
murilolima commented 2 years ago

Edit the file DropDown.js and modify Line 29 to

} else {
  setDisplayValue('');
}
DrPolymath commented 2 years ago

Thank you!

Venkat1P commented 2 years ago

Thanks @murilolima Above solution worked well. Do you have any plan to add this to next release.

bombillazo commented 2 years ago

Please add a way to clear the input value. I know you're working on a new version of this package but there are various improvements that could be made while we wait, this being one of them!

Venkat1P commented 1 month ago

Thanks @fateh999