Skip to content

Commit

Permalink
feat: add option for search input type (#471)
Browse files Browse the repository at this point in the history
Closes #441

Add an `inputType` prop allowing users to switch to a search input
  • Loading branch information
csandman authored Jul 27, 2020
1 parent 03e647b commit 58264de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ Default: `nope`

Autocomplete input attribute.

#### inputType
Type: `String`,
Default: `text`

The value for the `type` attribute on the html input element. Can be either `text` or `search`.

#### Others

All [allowed attributes for `input[type="text"]`](https://github.com/ubilabs/react-geosuggest/blob/master/src/filter-input-attributes.ts#L4)
Expand Down
1 change: 1 addition & 0 deletions src/Geosuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ export default class extends React.Component<IProps, IState> {
onBlur={this.onInputBlur}
onKeyDown={this.props.onKeyDown}
onKeyPress={this.props.onKeyPress}
inputType={this.props.inputType}
onNext={this.onNext}
onPrev={this.onPrev}
onSelect={this.onSelect}
Expand Down
3 changes: 2 additions & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export default {
placeholder: 'Search places',
queryDelay: 250,
skipSuggest: () => false,
style: {}
style: {},
inputType: 'text'
};
4 changes: 3 additions & 1 deletion src/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IProps {
readonly activeSuggest: ISuggest | null;
readonly listId: string;
readonly label?: string;
readonly inputType: string;
readonly onChange: (value: string) => void;
readonly onSelect: () => void;
readonly onKeyDown?: (event: React.KeyboardEvent) => void;
Expand All @@ -43,6 +44,7 @@ export default class Input extends React.PureComponent<IProps, {}> {
className: '',
isSuggestsHidden: true,
listId: '',
inputType: 'text',
onBlur: () => {},
onChange: () => {},
onEscape: () => {},
Expand Down Expand Up @@ -168,7 +170,7 @@ export default class Input extends React.PureComponent<IProps, {}> {
className={classes}
id={`geosuggest__input${this.props.id ? `--${this.props.id}` : ''}`}
ref={(i): HTMLInputElement | null => (this.input = i)}
type="text"
type={this.props.inputType}
{...attributes}
value={this.props.value}
style={this.props.style}
Expand Down
1 change: 1 addition & 0 deletions src/types/props.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export default interface IProps {
readonly autoComplete?: string;
readonly minLength?: number;
readonly placeDetailFields?: string[] | null;
readonly inputType?: string;
}

0 comments on commit 58264de

Please sign in to comment.