Skip to content

Commit 033c8e1

Browse files
authored
Merge pull request #767 from Sujalkumar12/feature/clear-text-on-select-item
feat: add clear search field functionality on item select
2 parents 68a88dc + cf54a48 commit 033c8e1

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ declare module 'react-native-dropdown-picker' {
196196
containerStyle?: StyleProp<ViewStyle>;
197197
customItemContainerStyle?: StyleProp<ViewStyle>;
198198
customItemLabelStyle?: StyleProp<TextStyle>;
199+
clearSearchFieldOnSelect?: boolean;
199200
customItemValueDelimiter?: string;
200201
disableBorderRadius?: boolean;
201202
disabledItemContainerStyle?: StyleProp<ViewStyle>;

src/components/Picker.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function Picker({
8484
containerStyle = {},
8585
customItemContainerStyle = {},
8686
customItemLabelStyle = {},
87+
clearSearchFieldOnSelect = false,
8788
customItemValueDelimiter = '-',
8889
disableBorderRadius = true,
8990
disabled = false,
@@ -350,6 +351,19 @@ function Picker({
350351
if (mode === MODE.SIMPLE) badgeFlatListRef.current = null;
351352
}, [mode]);
352353

354+
/**
355+
* clear search field on item select.
356+
*/
357+
useEffect(() => {
358+
if (
359+
clearSearchFieldOnSelect == true &&
360+
multiple == true &&
361+
searchText.length > 0
362+
) {
363+
setSearchText('');
364+
}
365+
}, [value]);
366+
353367
/**
354368
* onPressClose.
355369
*/

0 commit comments

Comments
 (0)