Coder Social home page Coder Social logo

hibiken / react-places-autocomplete Goto Github PK

View Code? Open in Web Editor NEW
1.4K 18.0 386.0 1.98 MB

React component for Google Maps Places Autocomplete

Home Page: https://hibiken.github.io/react-places-autocomplete/

License: MIT License

JavaScript 100.00%
react autocomplete google-maps google-api component geocoder

react-places-autocomplete's Introduction

MIT-License Gitter Maintainers Wanted

We are looking for maintainers!

In order to ensure active development going forward, we are looking for maintainers to join the project. Please contact the project owner if you are interested.

React Places Autocomplete

A React component to build a customized UI for Google Maps Places Autocomplete

Demo

Live demo: hibiken.github.io/react-places-autocomplete/

Features

  1. Enable you to easily build a customized autocomplete dropdown powered by Google Maps Places Library
  2. Utility functions to geocode and get latitude and longitude using Google Maps Geocoder API
  3. Full control over rendering to integrate well with other libraries (e.g. Redux-Form)
  4. Mobile friendly UX
  5. WAI-ARIA compliant
  6. Support Asynchronous Google script loading

Installation

To install the stable version

npm install --save react-places-autocomplete

React component is exported as a default export

import PlacesAutocomplete from 'react-places-autocomplete';

utility functions are named exports

import {
  geocodeByAddress,
  geocodeByPlaceId,
  getLatLng,
} from 'react-places-autocomplete';

Getting Started

To use this component, you are going to need to load Google Maps JavaScript API

Load the library in your project

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>

Create your component

import React from 'react';
import PlacesAutocomplete, {
  geocodeByAddress,
  getLatLng,
} from 'react-places-autocomplete';

class LocationSearchInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = { address: '' };
  }

  handleChange = address => {
    this.setState({ address });
  };

  handleSelect = address => {
    geocodeByAddress(address)
      .then(results => getLatLng(results[0]))
      .then(latLng => console.log('Success', latLng))
      .catch(error => console.error('Error', error));
  };

  render() {
    return (
      <PlacesAutocomplete
        value={this.state.address}
        onChange={this.handleChange}
        onSelect={this.handleSelect}
      >
        {({ getInputProps, suggestions, getSuggestionItemProps, loading }) => (
          <div>
            <input
              {...getInputProps({
                placeholder: 'Search Places ...',
                className: 'location-search-input',
              })}
            />
            <div className="autocomplete-dropdown-container">
              {loading && <div>Loading...</div>}
              {suggestions.map(suggestion => {
                const className = suggestion.active
                  ? 'suggestion-item--active'
                  : 'suggestion-item';
                // inline style for demonstration purpose
                const style = suggestion.active
                  ? { backgroundColor: '#fafafa', cursor: 'pointer' }
                  : { backgroundColor: '#ffffff', cursor: 'pointer' };
                return (
                  <div
                    {...getSuggestionItemProps(suggestion, {
                      className,
                      style,
                    })}
                  >
                    <span>{suggestion.description}</span>
                  </div>
                );
              })}
            </div>
          </div>
        )}
      </PlacesAutocomplete>
    );
  }
}

Props

PlacesAutocomplete is a Controlled Component with a Render Prop. Therefore, you MUST pass at least value and onChange callback to the input element, and render function via children.

Prop Type Required Description
value string value for the input element
onChange function onChange function for the input element
children function Render function to specify the rendering
onSelect function Event handler to handle user's select event
onError function Error handler function that gets called when Google Maps API responds with an error
searchOptions object Options to Google Maps API (i.e. bounds, radius)
debounce number Number of milliseconds to delay before making a call to Google Maps API
highlightFirstSuggestion boolean If set to true, first list item in the dropdown will be automatically highlighted
shouldFetchSuggestions boolean Component will hit Google Maps API only if this flag is set true
googleCallbackName string You can provide a callback name to initialize PlacesAutocomplete after google script is loaded

value

Type: string, Required: true

onChange

Type: function, Required: true

Typically this event handler will update value state.

<PlacesAutocomplete
  value={this.state.value}
  onChange={value => this.setState({ value })}
>
  {/* custom render function */}
</PlacesAutocomplete>

children

Type: function Required: true

This is where you render whatever you want to based on the state of PlacesAutocomplete. The function will take an object with the following keys.

  • getInputProps : function
  • getSuggestionItemProps : function
  • loading : boolean
  • suggestions : array

Simple example

const renderFunc = ({ getInputProps, getSuggestionItemProps, suggestions }) => (
  <div className="autocomplete-root">
    <input {...getInputProps()} />
    <div className="autocomplete-dropdown-container">
      {loading && <div>Loading...</div>}
      {suggestions.map(suggestion => (
        <div {...getSuggestionItemProps(suggestion)}>
          <span>{suggestion.description}</span>
        </div>
      ))}
    </div>
  </div>
);

// In render function
<PlacesAutocomplete value={this.state.value} onChange={this.handleChange}>
  {renderFunc}
</PlacesAutocomplete>;

getInputProps

This function will return the props that you can spread over the <input /> element. You can optionally call the function with an object to pass other props to the input.

// In render function
<input {...getInputProps({ className: 'my-input', autoFocus: true })} />

getSuggestionItemProps

This function will return the props that you can spread over each suggestion item in your autocomplete dropdown. You MUST call it with suggestion object as an argument, and optionally pass an object to pass other props to the element.

// Simple example
<div className="autocomplete-dropdown">
  {suggestions.map(suggestion => (
    <div {...getSuggestionItemProps(suggestion)}>
      {suggestion.description}
    </div>
  ))}
</div>

// Pass options as a second argument
<div className="autocomplete-dropdown">
  {suggestions.map(suggestion => {
    const className = suggestion.active ? 'suggestion-item--active' : 'suggestion-item';
    return (
      <div {...getSuggestionItemProps(suggestion, { className })}>
        {suggestion.description}
      </div>
    );
  })}
</div>

loading

This is a boolean flag indicating whether or not the request is pending, or has completed.

suggestions

This is an array of suggestion objects each containing all the data from Google Maps API and other metadata.

An example of a suggestion object.

{
  active: false,
  description: "San Francisco, CA, USA",
  formattedSuggestion: { mainText: "San Francisco", secondaryText: "CA, USA" },
  id: "1b9ea3c094d3ac23c9a3afa8cd4d8a41f05de50a",
  index: 0,
  matchedSubstrings: [ {length: 8, offset: 0} ],
  placeId: "ChIJIQBpAG2ahYAR_6128GcTUEo",
  terms: [
    { offset: 0, value: "San Francisco" },
    { offset: 15, value: "CA" },
    { offset: 19, value: "USA" }
  ],
  types: ["locality", "political", "geocode"]
}

onSelect

Type: function Required: false, Default: null

You can pass a function that gets called instead of onChange function when user hits the Enter key or clicks on a suggestion item.

The function takes three positional arguments. First argument is address, second is placeId and third is the entire suggestion object.

// NOTE: `placeId` and `suggestion` are null when user hits Enter key with no suggestion item selected.
const handleSelect = (address: string, placeId: ?string, suggestion: ?object) => {
  // Do something with address and placeId and suggestion
}

// Pass this function via onSelect prop.
<PlacesAutocomplete
  value={this.state.value}
  onChange={this.handleChange}
  onSelect={this.handleSelect}
>
  {/* Custom render function */}
</PlacesAutocomplete>

onError

Type: function Required: false

You can pass onError prop to customize the behavior when google.maps.places.PlacesServiceStatus is not OK (e.g., no predictions are found)

Function takes status (string) and clearSuggestions (function) as parameters

// Log error status and clear dropdown when Google Maps API returns an error.
const onError = (status, clearSuggestions) => {
  console.log('Google Maps API returned error with status: ', status)
  clearSuggestions()
}

<PlacesAutocomplete
  value={this.state.value}
  onChange={this.handleChange}
  onError={onError}
>
  {/* Custom render function */}
</PlacesAutocomplete>

searchOptions

Type: Object Required: false Default: {}

You can fine-tune the settings passed to the AutocompleteService class with searchOptions prop. This prop accepts an object following the same format as google.maps.places.AutocompletionRequest (except for input, which comes from the value of the input field).

// these options will bias the autocomplete predictions toward Sydney, Australia with a radius of 2000 meters,
// and limit the results to addresses only
const searchOptions = {
  location: new google.maps.LatLng(-34, 151),
  radius: 2000,
  types: ['address']
}

<PlacesAutocomplete
  value={this.state.value}
  onChange={this.handleChange}
  searchOptions={searchOptions}
>
  {/* Custom render function */}
</PlacesAutocomplete>

debounce

Type: number Required: false Default: 200

The number of milliseconds to delay before making a call to Google Maps API.

highlightFirstSuggestion

Type: boolean Required: false Default: false

If set to true, first suggestion in the dropdown will be automatically set to be active.

shouldFetchSuggestions

Type: boolean Required: false Default: true

// Only fetch suggestions when the input text is longer than 3 characters.
<PlacesAutocomplete
  value={this.state.address}
  onChange={this.handleChange}
  shouldFetchSuggestions={this.state.address.length > 3}
>
  {/* custom render function */}
</PlacesAutocomplete>

googleCallbackName

Type: string Required: false Default: undefined

If provided, component will initialize after the browser has finished downloading google script.

IMPORTANT: To enable this async mode, you need to provide the same callback name to google script via callback=[YOUR CALLBACK NAME].

Example:

<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=myCallbackFunc"></script>

Then, provide googleCallbackName prop to PlacesAutocomplete.

<PlacesAutocomplete
  value={this.state.value}
  onChange={this.handleChange}
  googleCallbackName="myCallbackFunc"
>
  {/* custom render function */}
</PlacesAutocomplete>

NOTE: If there are more than one PlacesAutocomplete components rendered in the page, set up a callback function that calls a callback function for each component.

Example:

<script>
window.myCallbackFunc = function() {
  window.initOne && window.initOne();
  window.initTwo && window.initTwo();
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=myCallbackFunc"></script>
<PlacesAutocomplete
  value={this.state.value}
  onChange={this.handleChange}
  googleCallbackName="initOne"
>
  {/* custom render function */}
</PlacesAutocomplete>

<PlacesAutocomplete
  value={this.state.value}
  onChange={this.handleChange}
  googleCallbackName="initTwo"
>
  {/* custom render function */}
</PlacesAutocomplete>

Utility Functions

geocodeByAddress API

/**
 * Returns a promise
 * @param {String} address
 * @return {Promise}
 */
geocodeByAddress(address);

address

Type: String, Required: true

String that gets passed to Google Maps Geocoder

import { geocodeByAddress } from 'react-places-autocomplete';

// `results` is an entire payload from Google API.
geocodeByAddress('Los Angeles, CA')
  .then(results => console.log(results))
  .catch(error => console.error(error));

geocodeByPlaceId API

/**
 * Returns a promise
 * @param {String} placeId
 * @return {Promise}
 */
geocodeByPlaceId(placeId);

placeId

Type: String, Required: true

String that gets passed to Google Maps Geocoder

import { geocodeByPlaceId } from 'react-places-autocomplete';

// `results` is an entire payload from Google API.
geocodeByPlaceId('ChIJE9on3F3HwoAR9AhGJW_fL-I')
  .then(results => console.log(results))
  .catch(error => console.error(error));

getLatLng API

/**
 * Returns a promise
 * @param {Object} result
 * @return {Promise}
 */
getLatLng(result);

result

Type: Object Required: true

One of the element from results (returned from Google Maps Geocoder)

import { geocodeByAddress, getLatLng } from 'react-places-autocomplete';

geocodeByAddress('Tokyo, Japan')
  .then(results => getLatLng(results[0]))
  .then(({ lat, lng }) =>
    console.log('Successfully got latitude and longitude', { lat, lng })
  );

Discussion

Join us on Gitter if you are interested in contributing!

License

MIT

react-places-autocomplete's People

Contributors

alexandrekilian avatar cburbank avatar codetriage-readme-bot avatar dependabot[bot] avatar emanualjade avatar hibiken avatar jmlag avatar jonabrams avatar jruhland avatar lightcap avatar markph1990 avatar paul-taiwo avatar sambokai avatar spykr avatar tkrotoff avatar viperfx07 avatar xiex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-places-autocomplete's Issues

'type' in new inputProps, what does it do?

In the 5.0.0 update, there is a new prop called 'type' in inputProps

const inputProps = {
value,
onChange,
onBlur: () => {
console.log('blur!')
},
type: 'search',
placeholder: 'Search Places...',
autoFocus: true,
}

What does this prop do? This is just a guess, but does it control the type of request the component uses (PlaceSearchRequest vs AutocompletionRequest)? I'm looking to search for a specific type of place which isn't supported in AutocompletionRequest.

Get establishment name

I saw the four types mentioned in the Places docs.

I see how I can limit the autocomplete to establishments, but is there a way to specifically get the establishment name in addition to its address? So instead of "John's Restaurant, Pasadena, CA, USA", I would like to get "John's Restaurant".

This answer mentions it's possible, but React-Places-Autocomplete only returns an address, not a place_id or anything else. So I'm not sure how to make it work…?

Allow autoFocus prop for input

Allow an autoFocus prop that is sent down to the element. Useful for pages when the component is the main function.

Thanks for the great component!

Why select text then type, append to value but not remplace ?

1 - I write : "Paris, Fra"
2 - I select all the text "Paris, Fra"
3 - I write : "London"
4 - It gives me : "Paris, FraLondon"


Excepted

1 - I write : "Paris, Fra"
2 - I select all the text "Paris, Fra"
3 - I write : "London"
4 - Removes "Paris, Fra"
5 - It gives me : "London"

Thanks!

Is debounce supported?

Hello!, is debounce supported?, tryed to implement it with lodash but it seems that is tight coupled with the component.

How to get Address by Longitude and Latitude?

I use geocodeByAddress to find address, it works.

But If I type an approximative address, I have this result : this address is not correct but the long and lat is correct.

Now, how to use Long and Lat to find the real address please?

Thanks.

Pass input name as a prop

It would be a "nice to have" if the the input name could be passed as a prop. This would make it easier for acceptance testing to have an HTML hook to use.

Autocomplete doesn't work on mobile

The places autocomplete doesn't work on my mobile phone, has anyone been able to use it on mobile? Excuse me if this issue has already been presented, I could not find it elsewhere

👂 Accessibility for screenreaders

I was testing this component with a screenreader and found a couple issues with the display of the autocomplete suggestions. When listening to the screenreader there is no way to know that a dropdown with suggestions has appeared as you type into the input.

Consider these two fairly simple options.

Option 1: provide a visually-hidden <span> that says to arrow down for autocomplete suggestions

<span class="visually-hidden" id="autocomplete-description">Arrow down for autocomplete suggestions</span>
<div aria-describedby="autocomplete-description" id="PlacesAutocomplete__autocomplete-container ... />

or Option 2: add the aria-live="polite" attribute so the screenreader will automatically start reading the suggestions as you type into the input.

<div aria-live="polite" id="PlacesAutocomplete__autocomplete-container ... >

I have tested both options with a screenreader and both work nicely to add a bit more accessibility to the autocomplete. If you like any of these suggestions I'd be happy to make a PR. 😁

Side note: I also noticed that the input has no <label> which is an accessibility requirement. This one isn't so much of an issue, as the developer using the component can easily add a <label> and the inputId={...} prop, but could also be solved by including a aria-label attribute by default.

Selection of autocomplete doesn't work on mobile (iOS Safari)

due to this part here, only mouse events are valid for selection

onMouseOver={() => this.setActiveItemAtIndex(p.index)}
onMouseDown={() => this.selectAddress(p.suggestion, p.placeId)}

changing onMouseDown to onClick or adding onTouchEnd and onTouchStart events should fix this.

Uncaught TypeError: Cannot read property 'lat' of null

Hi,

Would it be possible to manually resolve errors within the geocodeByAddress callback? I am unable to reference my error in order to show it to my users.

Uncaught TypeError: Cannot read property 'lat' of null
    at LocationForm.js:38
    at utils.js:12
    at geocoder.js:5
    at geocoder.js:3
    at jS (geocoder.js:2)
    at Im.<anonymous> (geocoder.js:3)
    at common.js:52
    at Pm.f (common.js:33)
    at Im.en (common.js:52)
    at Object.c [as _2rqwmm] (common.js:46)

Need to pass id to the input field

Hi,
Is there a way to pass 'id' attribute to the input field of "PlacesAutocomplete". I need it so that when I click on the label for the input field, the input field will receive focus.
Thanks

warning for React.PropType

I am getting this warning after adding the component to my project:

Warning: You are manually calling a React.PropTypes validation function for the autoFocus prop on PlacesAutocomplete. This is deprecated and will not work in production with the next major version. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.

If you follow instruction in https://fb.me/react-warning-dont-call-proptypes , you can fix this warning that everyone, who is using this library, is getting.

Thank you

type "rfdlsfdmgjdflk" return Cannot read property 'lat' of null

When I type "gdfg fdg ...G. DF GDFG FD", I have an real error.

Cannot read property 'lat' of null


Excepted :
STATUS : ZERO_RESULT


Solution :
if result[0] exist define lat : results[0].geometry.location.lat(
else lat : 0

Something like that.


Inside this function :

    geocoder.geocode({ address: address }, function (results, status) {
       if (status !== OK) {
         callback({ status: status }, null, results);
         return;
      }
      var latLng = {
        lat: results[0].geometry.location.lat(),
        lng: results[0].geometry.location.lng()
      };

      callback(null, latLng, results);
   });

`onEnterKeyDown` does not trigger when no autocomplete item exists.

handleEnterKey exists prematurely if autocompleteItems is empty.

It seems like this behavior was added in #53 as a response to an exception caused in handleKeyDown and it's subsequent call to selectActiveItemAtIndex. However handleEnterKey does not use the selectActiveItemAtIndex function so this check does not appear necessary, and prevents the onEnterKeyDown callback from triggering.

Move from inline styling to CSS based for easier overriding

Currently styling is set inline with defaultStyles.js, you can easily override the className of the autocomplete container but you cannot easily override it's styling because the styles are set inline.

Proposal

Move default styling to CSS or SCSS so the user can import the styling and override without touching Js.

This request has been blocked; the content must be served over HTTPS.

Hello, thank you for the repo!

I ran into this problem while serving in prod :

Mixed Content: The page at 'https://MyUrl.com' was loaded over HTTPS, but requested an insecure resource 'http://maps.googleapis.com/maps/api/geocode/json?latlng=46.19018519999999,6.1402054000000135'. This request has been blocked; the content must be served over HTTPS.

Also I am using this repo but I don't know which repo is causing the error.

return placeID?

It looks like the component is discarding the placeID instead of using it to retrieve the coordinates via geocode.

I assume that addresses are usually 1:1 with geocode when taken directly from Places results, but would it be safer to geocode on placeID instead?

At the very least, it'd be helpful if placeID was returned along with suggestion

On autocomplete fail callback

@kenny-hibino

It could be useful to allow users to pass in a callback to execute when PlacesServiceStatus is not OK (i.e., no predictions were found). Currently it writes an error message to the console.

Along those same lines - when autocomplete fails, the current predictions aren't cleared so the autocomplete items remain visible. Do you think it would make sense to give the option of clearing the autocomplete items on fail? It could be a boolean prop, maybe clearItemsOnFail or something like that.

If this sounds good to you I'd be happy to do it and open a PR.

Thanks!

Any plans to add radius?

This package looks great. Any plans to add radius filtering to limit results? I've seen other where you can pass in a location or country and limit results to a certain radius.

Thanks!

Demo link?

Hi @kenny-hibino, thank you for putting out this library! I was wondering if you had any plans to put out a demo link, so one could test the functionality easily?

Also, was curious how it compares to react-geosuggest in your opinion?

Thank you!

How to refer to input inside the component?

I want to focus input element after the component did mount.
Case example: The user clicks change button after that the search input will be focused.

How to refer to input inside the component?

Is it possible to bind API key via runtime env variable?

Currently, you have to insert JS in main html file, like this:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=___API_KEY___&libraries=places"></script>

Would it be possible, perhaps in a future version, to add the API key & Google Places API inside the code, like this? That way the API key remains hidden in production.
geocodeByAddress.key(process.env.REACT_APP_GOOGLE_API_KEY)

Thank you 🙏🏽

Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.

I'm getting this warning,
Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.

printWarning @ warning.js:36
warning @ warning.js:60
get @ React.js:95
162../defaultStyles @ PlacesAutocomplete.js:352
s @ _prelude.js:1
(anonymous) @ _prelude.js:1
164../PlacesAutocomplete @ index.js:8
s @ _prelude.js:1
(anonymous) @ _prelude.js:1
6.react @ jobs_search_form.js:3
s @ _prelude.js:1
(anonymous) @ _prelude.js:1
(anonymous) @ components.js:3
3../components/job @ components.js:5
s @ _prelude.js:1
(anonymous) @ _prelude.js:1
(anonymous) @ _stream_0.js:29
2../components @ _stream_0.js:37
s @ _prelude.js:1
e @ _prelude.js:1
(anonymous) @ _prelude.js:1

Enter key on the input without a selection should trigger form onSubmit or have a callback prop

First off, thanks for this simple and focused component, it is what I was looking for and has a clean API.

It would be nice if Enter in the input would actually submit something, since it would be parity with normal form behavior. Right now it does not, which after a cursory glance at the code is likely a result of the if (activeItem === undefined) { return } in handleEnterKey()

handleEnterKey() {
    const activeItem = this._getActiveItem()
    if (activeItem === undefined) { return }

    this.selectAddress(activeItem.suggestion, activeItem.placeId)
  }

I would suggest adding an onEnter callback prop that receives the first result item, and the current value of the text input, or simply trigger onSubmit with the current text or first result item.

npm package version doesn't match repo tags or releases

Hi,

I'm using version 4.1.3 of this library and npm outdated is showing there is a new version of 5.0.0. I was wondering if you could provide a changelog or more detailed release notes on what has changed in this update as it is a sem-ver major update. In this repo the last release version was 2.8.0, same with the tags so it's not really possible to do a proper diff and see if there are any breaking changes. Any extra information on this latest update would be appreciated!

Add matching_substrings property to autocompleteItems and formattedSuggestion

Hello!

I'm using your component and I need to highlight matching parts of predictions and user's input string.
As I know, in predictions set, returned by request, there is property 'matched_substrings' with the set of matches' length and offset.
Is it possible to add this property both to autocompleteItems and to formattedSuggestion, so it is possible to access matches through "render" using "autocompleteItem" property?

Or even do like this:
const formattedSuggestion = (structured_formatting) => ({
mainText: structured_formatting.main_text,
secondaryText: structured_formatting.secondary_text,
mainTextMatchedSubstrings: structured_formatting.main_text_matched_substrings,
secondaryTextMatchedSubstrings: structured_formatting.secondary_text_matched_substrings
});

main_text_matched_substrings and secondary_text_matched_substrings are contained in the structured_formatting of prediction, so it is possible to add it exactly to formatting function

Allow custom input component

Hi @kenny-hibino ,

Have you considered allowing the choice of using a custom input component? That would be useful if you want to add autocomplete functionality to an existing input component (e.g., part of a different library). The PlacesAutocomplete component could act as a wrapper, with the component you want to add the autocomplete functionality to as its child. So it would look like:

<PlacesAutocomplete value={value} onChange={this.handleChange}><MyCustomInputComponent /></PlacesAutocomplete>

If you think this feature would make sense to add, I'd be happy to take a shot and open a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.