getaddress-autocomplete-modal
Version:
GetAddress.io - Autocomplete modal plug-in
40 lines • 1.65 kB
JavaScript
import SuggestionContainer from "./SuggestionContainer.js";
export default class SuggestionList {
constructor(client, modal, attributeValues) {
this.client = client;
this.modal = modal;
this.attributeValues = attributeValues;
this.list = document.createElement('DIV');
this.element = this.list;
this.build = () => {
this.list.id = this.attributeValues.suggestionListId;
this.list.className = this.attributeValues.suggestionListClassName;
this.list.style.display = 'none';
this.list.setAttribute('role', 'listbox');
this.list.addEventListener('mouseenter', this.handleMouseEnter);
this.list.addEventListener('click', this.handleClick);
};
this.handleMouseEnter = () => { };
this.handleClick = () => { };
this.populate = (suggestions) => {
this.clear();
suggestions.forEach(suggestion => {
var container = new SuggestionContainer(this.client, this.modal, suggestion, this.attributeValues);
this.list.insertBefore(container.element, null);
});
if (suggestions.length > 0) {
this.list.style.display = 'block';
}
};
this.clear = () => {
this.list.replaceChildren(...[]);
this.list.style.display = 'none';
};
this.build();
}
destroy() {
this.list.removeEventListener('mouseenter', this.handleMouseEnter);
this.list.removeEventListener('click', this.handleClick);
}
}
//# sourceMappingURL=SuggestionList.js.map