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 Issues

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.

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!

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

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!

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

'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.

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.

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 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

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

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…?

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!

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);
   });

πŸ‘‚ 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.

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 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?

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

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.

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!

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.

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!

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)

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.

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

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.

`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.

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!

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.