From 109be2341e652cc0061d04681050035ee1fe4973 Mon Sep 17 00:00:00 2001 From: SujalKumar Date: Wed, 23 Oct 2024 22:39:22 +0530 Subject: [PATCH] feat: add clear search field functionality on item select --- index.d.ts | 1 + src/components/Picker.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/index.d.ts b/index.d.ts index 0e0dd54..ade36f5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -196,6 +196,7 @@ declare module 'react-native-dropdown-picker' { containerStyle?: StyleProp; customItemContainerStyle?: StyleProp; customItemLabelStyle?: StyleProp; + clearSearchFieldOnSelect?: boolean; disableBorderRadius?: boolean; disabledItemContainerStyle?: StyleProp; disabledItemLabelStyle?: StyleProp; diff --git a/src/components/Picker.js b/src/components/Picker.js index eb3bed6..e94bf46 100644 --- a/src/components/Picker.js +++ b/src/components/Picker.js @@ -83,6 +83,7 @@ function Picker({ containerStyle = {}, customItemContainerStyle = {}, customItemLabelStyle = {}, + clearSearchFieldOnSelect = false, disableBorderRadius = true, disabled = false, disabledItemContainerStyle = {}, @@ -348,6 +349,19 @@ function Picker({ if (mode === MODE.SIMPLE) badgeFlatListRef.current = null; }, [mode]); + /** + * clear search field on item select. + */ + useEffect(() => { + if ( + clearSearchFieldOnSelect == true && + multiple == true && + searchText.length > 0 + ) { + setSearchText(''); + } + }, [value]); + /** * onPressClose. */