Skip to content

Commit

Permalink
Fix: Guard against 'null' description when losing focus (fixes #19) (#20
Browse files Browse the repository at this point in the history
)

There is an issue where if you search and render suggestions for the
first time (i.e. a suggestion hasn't been selected yet) and click away
so taht focus is lost then you will receive an error of the form:
"Uncaught TypeError: Cannot read property 'description' of null". This
error occurs in the function we pass to the 'itemToString' prop when
rendering the <Downshift> component. Its a result of no suggestions
being available yet trying to destructure the 'description' property off
of a suggestion.

This commit provides a fix to guard against the case where there are no
suggestions, in which case we simply return the empty string.
	modified:   src/MUIPlacesAutocomplete.jsx
  • Loading branch information
Giners committed Jan 30, 2018
1 parent b0781f7 commit 27336be
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/MUIPlacesAutocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default class MUIPlacesAutocomplete extends React.Component {
<Downshift
onSelect={this.onSuggestionSelected}
onInputValueChange={this.onInputValueChange}
itemToString={({ description }) => description}
itemToString={suggestion => (suggestion ? suggestion.description : '')}
render={this.renderAutocomplete}
/>
)
Expand Down

0 comments on commit 27336be

Please sign in to comment.