Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
fix(events): ensure clear event is emitted after setVal is called (#456)
Browse files Browse the repository at this point in the history
places directly used autocomplete's setVal which caused issue
when the user cleared the input field right after
where no clear events would be emitted
  • Loading branch information
JonathanMontane authored Dec 14, 2017
1 parent 9c35a95 commit c84b7aa
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,26 @@ export default function places(options) {
.querySelector(`.${prefix}-input`)
.addEventListener('input', inputListener);

const autocompleteMethods = ['open', 'close', 'getVal', 'setVal', 'destroy'];
autocompleteMethods.forEach(methodName => {
const autocompleteIsomorphicMethods = ['open', 'close', 'getVal'];
autocompleteIsomorphicMethods.forEach(methodName => {
placesInstance[methodName] = (...args) => {
if (methodName === 'destroy') {
// this is the only event we need to manually remove because the input will still be here
autocompleteContainer
.querySelector(`.${prefix}-input`)
.removeEventListener('input', inputListener);
}

autocompleteInstance.autocomplete[methodName](...args);
};
});

placesInstance.destroy = (...args) => {
autocompleteContainer
.querySelector(`.${prefix}-input`)
.removeEventListener('input', inputListener);

autocompleteInstance.autocomplete.destroy(...args);
};

placesInstance.setVal = (...args) => {
previousQuery = args[0];
autocompleteInstance.autocomplete.setVal(...args);
};

placesInstance.autocomplete = autocompleteInstance;

return placesInstance;
Expand Down

0 comments on commit c84b7aa

Please sign in to comment.