bug corregido para anterior refactor en dropDown

This commit is contained in:
Daniel Herrero 2017-12-12 13:59:31 +01:00
parent 6d1bbfe6c2
commit 93c915ec26
1 changed files with 36 additions and 18 deletions

View File

@ -17,6 +17,7 @@ export default class DropDown {
get container() { get container() {
return this.$element[0].querySelector('ul.dropdown'); return this.$element[0].querySelector('ul.dropdown');
} }
get show() { get show() {
return this._show; return this._show;
} }
@ -32,10 +33,7 @@ export default class DropDown {
} else { } else {
this._tryToShow = 0; this._tryToShow = 0;
this._show = value; this._show = value;
this._setFocusInFilterInput(value, oldValue); this._toggleDropDown(value, oldValue);
this.$timeout(() => {
this._calculatePosition(value, oldValue);
});
} }
} }
@ -71,8 +69,32 @@ export default class DropDown {
}); });
} }
_toggleDropDown(value, oldValue) {
if (value && !this._focusingFilter && !oldValue && this.filter) {
// open dropDown
this._setFocusInFilterInput();
this._eventScroll(true);
} else if (!value && oldValue) {
// close dropDown
this._eventScroll(false);
}
this.$timeout(() => {
this._calculatePosition(value, oldValue);
});
}
_eventScroll(add) {
if (add) {
this.$timeout(() => { // wait angular ngIf
this.container.addEventListener('scroll', e => this.loadFromScroll(e));
});
} else {
this.container.removeEventListener('scroll', e => this.loadFromScroll(e));
}
}
_setFocusInFilterInput(value, oldValue) { _setFocusInFilterInput(value, oldValue) {
if (value && !this._focusingFilter && oldValue !== value && this.filter) {
this.$timeout(() => { this.$timeout(() => {
let inputFilterSearch = this.$element[0].querySelector('input'); let inputFilterSearch = this.$element[0].querySelector('input');
this._focusingFilter = true; this._focusingFilter = true;
@ -83,7 +105,7 @@ export default class DropDown {
}, 250); }, 250);
}); });
} }
}
_background(create) { _background(create) {
let el = document.getElementById('ddBack'); let el = document.getElementById('ddBack');
if (el) { if (el) {
@ -230,14 +252,10 @@ export default class DropDown {
$onInit() { $onInit() {
if (this.parent) if (this.parent)
this.parent.addEventListener('keydown', e => this.onKeydown(e)); this.parent.addEventListener('keydown', e => this.onKeydown(e));
if (this.container)
this.container.addEventListener('scroll', e => this.loadFromScroll(e));
} }
$onDestroy() { $onDestroy() {
if (this.parent) if (this.parent)
this.parent.removeEventListener('keydown', e => this.onKeydown(e)); this.parent.removeEventListener('keydown', e => this.onKeydown(e));
if (this.container)
this.container.removeEventListener('scroll', e => this.loadFromScroll(e));
} }
} }