Skip to content

Commit cca39cd

Browse files
committed
feat: support TextInput props passthrough and suggestion text display control
1 parent b8c44cf commit cca39cd

File tree

4 files changed

+169
-3
lines changed

4 files changed

+169
-3
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ A customizable React Native TextInput component for Google Places Autocomplete u
1616
- Extended place details fetching (Optional)
1717
- Compatible with both Expo and non-Expo projects
1818
- Works with Expo Web
19+
- Supports all TextInput props (autoCapitalize, keyboardType, etc.)
20+
- Control suggestion text display (lines, ellipsis)
1921

2022
## Preview
2123

@@ -201,6 +203,37 @@ const PlaceDetailsExample = () => {
201203
```
202204
</details>
203205

206+
<details>
207+
<summary>Example with TextInput props and suggestion text control</summary>
208+
209+
```javascript
210+
const CustomizedExample = () => {
211+
const handlePlaceSelect = (place) => {
212+
console.log('Selected place:', place);
213+
};
214+
215+
return (
216+
<GooglePlacesTextInput
217+
apiKey="YOUR_GOOGLE_PLACES_API_KEY"
218+
onPlaceSelect={handlePlaceSelect}
219+
// TextInput props
220+
autoCapitalize="words"
221+
autoCorrect={false}
222+
keyboardType="default"
223+
returnKeyType="search"
224+
textContentType="location"
225+
// Limit suggestion text to single line with ellipsis
226+
suggestionTextProps={{
227+
mainTextNumberOfLines: 1,
228+
secondaryTextNumberOfLines: 1,
229+
ellipsizeMode: 'tail',
230+
}}
231+
/>
232+
);
233+
};
234+
```
235+
</details>
236+
204237
## Props
205238

206239
| Prop | Type | Required | Default | Description |
@@ -235,6 +268,10 @@ const PlaceDetailsExample = () => {
235268
| hideOnKeyboardDismiss | boolean | No | false | Hide suggestions when keyboard is dismissed |
236269
| scrollEnabled | boolean | No | true | Enable/disable scrolling in the suggestions list |
237270
| nestedScrollEnabled | boolean | No | true | Enable/disable nested scrolling for the suggestions list |
271+
| suggestionTextProps | SuggestionTextProps | No | {} | Control suggestion text display (lines, ellipsis). [Details](./docs/styling-guide.md#suggestion-text-display-control) |
272+
| accessibilityLabels | GooglePlacesAccessibilityLabels | No | {} | Custom accessibility labels |
273+
| **TextInput Props** |
274+
| ...restProps | TextInputProps | No | - | All TextInput props supported. [Details](./docs/styling-guide.md#textinput-props-support) |
238275
| **Error Handling & Debugging** |
239276
| onError | (error: any) => void | No | - | Callback when API errors occur |
240277
| enableDebug | boolean | No | false | Enable detailed console logging for troubleshooting |
@@ -326,7 +363,7 @@ type Styles = {
326363
}
327364
```
328365
329-
For detailed styling examples and a complete guide, see our [Styling Guide](./docs/styling-guide.md).
366+
For detailed styling examples, TextInput props usage, and suggestion text control, see our [Styling Guide](./docs/styling-guide.md).
330367
331368
## Contributing
332369

docs/styling-guide.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,99 @@ The component automatically handles RTL layouts based on the text direction. You
320320
/>
321321
```
322322

323+
## TextInput Props Support
324+
325+
All standard React Native `TextInput` props are supported and can be passed directly to the component:
326+
327+
```javascript
328+
<GooglePlacesTextInput
329+
apiKey="YOUR_GOOGLE_PLACES_API_KEY"
330+
onPlaceSelect={handlePlaceSelect}
331+
// TextInput props
332+
autoCapitalize="words"
333+
autoCorrect={false}
334+
keyboardType="default"
335+
returnKeyType="search"
336+
textContentType="location"
337+
autoFocus={true}
338+
maxLength={100}
339+
editable={true}
340+
/>
341+
```
342+
343+
**Common TextInput props:**
344+
- `autoCapitalize` - Control auto-capitalization behavior
345+
- `autoCorrect` - Enable/disable auto-correction
346+
- `keyboardType` - Set keyboard type (default, email-address, numeric, phone-pad, etc.)
347+
- `returnKeyType` - Customize the return key (done, search, next, go, etc.)
348+
- `textContentType` - Optimize keyboard suggestions (iOS: location, streetAddressLine1, etc.)
349+
- `autoFocus` - Auto-focus the input on mount
350+
- `maxLength` - Limit input length
351+
- `editable` - Make the input read-only
352+
- `secureTextEntry`, `multiline`, `selectTextOnFocus`, and many more
353+
354+
See the [React Native TextInput documentation](https://reactnative.dev/docs/textinput#props) for a complete list.
355+
356+
## Suggestion Text Display Control
357+
358+
Control how suggestion text is displayed using the `suggestionTextProps` prop:
359+
360+
```typescript
361+
type SuggestionTextProps = {
362+
mainTextNumberOfLines?: number; // Max lines for place name
363+
secondaryTextNumberOfLines?: number; // Max lines for address
364+
ellipsizeMode?: 'head' | 'middle' | 'tail' | 'clip';
365+
}
366+
```
367+
368+
### Example: Single-line suggestions
369+
370+
```javascript
371+
<GooglePlacesTextInput
372+
apiKey="YOUR_GOOGLE_PLACES_API_KEY"
373+
onPlaceSelect={handlePlaceSelect}
374+
suggestionTextProps={{
375+
mainTextNumberOfLines: 1,
376+
secondaryTextNumberOfLines: 1,
377+
ellipsizeMode: 'tail',
378+
}}
379+
/>
380+
```
381+
382+
### Example: Two-line place name, one-line address
383+
384+
```javascript
385+
<GooglePlacesTextInput
386+
apiKey="YOUR_GOOGLE_PLACES_API_KEY"
387+
onPlaceSelect={handlePlaceSelect}
388+
suggestionTextProps={{
389+
mainTextNumberOfLines: 2,
390+
secondaryTextNumberOfLines: 1,
391+
ellipsizeMode: 'tail',
392+
}}
393+
/>
394+
```
395+
396+
### Example: Middle ellipsis
397+
398+
```javascript
399+
<GooglePlacesTextInput
400+
apiKey="YOUR_GOOGLE_PLACES_API_KEY"
401+
onPlaceSelect={handlePlaceSelect}
402+
suggestionTextProps={{
403+
mainTextNumberOfLines: 1,
404+
ellipsizeMode: 'middle', // "Very Long Pla...staurant Name"
405+
}}
406+
/>
407+
```
408+
409+
**Use cases:**
410+
- Limit vertical space usage in compact UIs
411+
- Prevent long place names/addresses from wrapping
412+
- Create a cleaner, more uniform suggestion list
413+
- Control where the ellipsis appears
414+
- Or allow unlimited lines by omitting `numberOfLines`
415+
323416
## Combining with Other Style Systems
324417

325418
If you're using a styling library like styled-components or Tailwind, you can still use this component by generating the style object:

src/GooglePlacesTextInput.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,34 @@ interface GooglePlacesAccessibilityLabels {
9393
suggestionItem?: (prediction: PlacePrediction) => string;
9494
}
9595

96-
type TextInputInheritedProps = Pick<TextInputProps, 'onFocus' | 'onBlur'>;
96+
interface SuggestionTextProps {
97+
/**
98+
* Maximum number of lines for the main text (place name)
99+
* @default undefined (no limit)
100+
*/
101+
mainTextNumberOfLines?: number;
102+
/**
103+
* Maximum number of lines for the secondary text (address)
104+
* @default undefined (no limit)
105+
*/
106+
secondaryTextNumberOfLines?: number;
107+
/**
108+
* Determines how text is truncated when it exceeds the number of lines
109+
* @default 'tail'
110+
*/
111+
ellipsizeMode?: 'head' | 'middle' | 'tail' | 'clip';
112+
}
97113

98-
interface GooglePlacesTextInputProps extends TextInputInheritedProps {
114+
interface GooglePlacesTextInputProps
115+
extends Omit<
116+
TextInputProps,
117+
| 'value'
118+
| 'onChangeText'
119+
| 'ref'
120+
| 'style'
121+
| 'placeholder'
122+
| 'placeholderTextColor'
123+
> {
99124
apiKey: string;
100125
value?: string;
101126
placeHolderText?: string;
@@ -124,6 +149,7 @@ interface GooglePlacesTextInputProps extends TextInputInheritedProps {
124149
onError?: (error: any) => void;
125150
enableDebug?: boolean;
126151
accessibilityLabels?: GooglePlacesAccessibilityLabels;
152+
suggestionTextProps?: SuggestionTextProps;
127153
}
128154

129155
interface GooglePlacesTextInputRef {
@@ -173,6 +199,8 @@ const GooglePlacesTextInput = forwardRef<
173199
onFocus,
174200
onBlur,
175201
accessibilityLabels = {},
202+
suggestionTextProps = {},
203+
...restTextInputProps
176204
},
177205
ref
178206
) => {
@@ -524,6 +552,8 @@ const GooglePlacesTextInput = forwardRef<
524552
style.suggestionText?.main,
525553
getTextAlign(),
526554
]}
555+
numberOfLines={suggestionTextProps.mainTextNumberOfLines}
556+
ellipsizeMode={suggestionTextProps.ellipsizeMode || 'tail'}
527557
>
528558
{mainText.text}
529559
</Text>
@@ -534,6 +564,8 @@ const GooglePlacesTextInput = forwardRef<
534564
style.suggestionText?.secondary,
535565
getTextAlign(),
536566
]}
567+
numberOfLines={suggestionTextProps.secondaryTextNumberOfLines}
568+
ellipsizeMode={suggestionTextProps.ellipsizeMode || 'tail'}
537569
>
538570
{secondaryText.text}
539571
</Text>
@@ -594,6 +626,7 @@ const GooglePlacesTextInput = forwardRef<
594626
<View style={[styles.container, style.container]}>
595627
<View>
596628
<TextInput
629+
{...restTextInputProps}
597630
ref={inputRef}
598631
style={[styles.input, style.input, getPadding(), getTextAlign()]}
599632
placeholder={placeHolderText}
@@ -767,6 +800,7 @@ export type {
767800
PlacePrediction,
768801
PlaceStructuredFormat,
769802
GooglePlacesAccessibilityLabels,
803+
SuggestionTextProps,
770804
};
771805

772806
export default GooglePlacesTextInput;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ export type {
1111
GooglePlacesTextInputProps,
1212
GooglePlacesTextInputRef,
1313
GooglePlacesTextInputStyles,
14+
GooglePlacesAccessibilityLabels,
15+
SuggestionTextProps,
1416
} from './GooglePlacesTextInput';

0 commit comments

Comments
 (0)