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. */