- Better handling of loading state

This commit is contained in:
fabien.leconte 2016-09-27 11:08:29 +02:00
parent e1151d5353
commit d5dbd44024

View file

@ -853,20 +853,27 @@ export default class Choices {
* @private
*/
_handleLoadingState(isLoading = true) {
let placeholderItem = this.itemList.querySelector('.' + this.config.classNames.placeholder);
if(isLoading) {
this.containerOuter.classList.add(this.config.classNames.loadingState);
this.containerOuter.setAttribute('aria-busy', 'true');
if (this.passedElement.type === 'select-one') {
const placeholderItem = this._getTemplate('placeholder', this.config.loadingText);
this.itemList.appendChild(placeholderItem);
if (!placeholderItem) {
placeholderItem = this._getTemplate('placeholder', this.config.loadingText);
this.itemList.appendChild(placeholderItem);
} else {
placeholderItem.innerHTML = this.config.loadingText;
}
} else {
this.input.placeholder = this.config.loadingText;
}
} else {
// Remove loading states/text
this.containerOuter.classList.remove(this.config.classNames.loadingState);
if (this.passedElement.type === 'select-multiple') {
const placeholder = this.config.placeholder ? this.config.placeholderValue || this.passedElement.getAttribute('placeholder') : false;
const placeholder = this.config.placeholder ? this.config.placeholderValue || this.passedElement.getAttribute('placeholder') : false;
if (this.passedElement.type === 'select-one') {
placeholderItem.innerHTML = placeholder || '';
} else {
this.input.placeholder = placeholder || '';
}
}