Skip to content

Commit 62bca6f

Browse files
committed
feat: add hideOnKeyboardDismiss prop to control suggestion visibility on keyboard dismiss
1 parent 13105eb commit 62bca6f

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ A customizable React Native TextInput component for Google Places Autocomplete u
44

55
## Features
66

7-
- 🎨 Fully customizable UI
8-
- ⌨️ Debounced search
9-
- 🗑️ Clear button (x)
10-
- 🔄 Loading indicator
11-
- 📱 Keyboard-aware
12-
- 🔍 Custom place types filtering
13-
- 🌍 RTL support
14-
- 🌐 Multi-language support
15-
- 🎯 TypeScript support
7+
- Fully customizable UI
8+
- Debounced search
9+
- Clear button (x)
10+
- Loading indicator
11+
- Keyboard-aware
12+
- Custom place types filtering
13+
- RTL support
14+
- Multi-language support
15+
- TypeScript support
1616

1717
## Preview
1818

@@ -172,6 +172,7 @@ const StyledExample = () => {
172172
| showLoadingIndicator | boolean | No | true | Show/hide loading indicator |
173173
| showClearButton | boolean | No | true | Show/hide the input clear button |
174174
| forceRTL | boolean | No | undefined | Force RTL layout direction |
175+
hideOnKeyboardDismiss | boolean | No | false | Hide suggestions when keyboard is dismissed
175176
| **Event Handlers** |
176177
| onPlaceSelect | (place: Place \| null) => void | Yes | - | Callback when place is selected |
177178
| onTextChange | (text: string) => void | No | - | Callback triggered on text input changes |

src/GooglePlacesTextInput.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const GooglePlacesTextInput = forwardRef(
4040
showClearButton = true,
4141
forceRTL = undefined,
4242
style = {},
43+
hideOnKeyboardDismiss = false,
4344
},
4445
ref
4546
) => {
@@ -60,15 +61,19 @@ const GooglePlacesTextInput = forwardRef(
6061

6162
// Add keyboard listener
6263
useEffect(() => {
63-
const keyboardDidHideSubscription = Keyboard.addListener(
64-
'keyboardDidHide',
65-
() => setShowSuggestions(false)
66-
);
64+
if (hideOnKeyboardDismiss) {
65+
const keyboardDidHideSubscription = Keyboard.addListener(
66+
'keyboardDidHide',
67+
() => setShowSuggestions(false)
68+
);
6769

68-
return () => {
69-
keyboardDidHideSubscription.remove();
70-
};
71-
}, []);
70+
return () => {
71+
keyboardDidHideSubscription.remove();
72+
};
73+
}
74+
// Return empty cleanup function if not using the listener
75+
return () => {};
76+
}, [hideOnKeyboardDismiss]);
7277

7378
// Expose methods to parent through ref
7479
useImperativeHandle(ref, () => ({

src/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ export interface GooglePlacesTextInputProps extends TextInputProps {
8989
* Whether to disable suggestions dropdown
9090
*/
9191
disableSuggestions?: boolean;
92+
93+
/**
94+
* Whether to hide suggestions when keyboard is dismissed
95+
* @default false
96+
*/
97+
hideOnKeyboardDismiss?: boolean;
9298
}
9399

94100
export interface GooglePrediction {

0 commit comments

Comments
 (0)