hibiken / react-places-autocomplete

React component for Google Maps Places Autocomplete
https://hibiken.github.io/react-places-autocomplete/
MIT License
1.38k stars 388 forks source link

Add matching_substrings property to autocompleteItems and formattedSuggestion #84

Open AlyonaPianykh opened 7 years ago

AlyonaPianykh commented 7 years ago

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

hibiken commented 7 years ago

@OlenaPianykh Thank you for opening this issue. I can see this feature is useful to other users too. I will add this feature. If you are interested, feel free to work on it and submit a PR too 👍

matthewgonzalez commented 6 years ago

Resurrecting this. I need this feature as well, so I went ahead and created the PR. The payload is coming from google so it just needed to be included in the component state.

sambokai commented 4 years ago

I left a comment on the PR and will merge once resolved! Hope you're still interested :)