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() {
return this.$element[0].querySelector('ul.dropdown');
}
get show() {
return this._show;
}
@ -32,10 +33,7 @@ export default class DropDown {
} else {
this._tryToShow = 0;
this._show = value;
this._setFocusInFilterInput(value, oldValue);
this.$timeout(() => {
this._calculatePosition(value, oldValue);
});
this._toggleDropDown(value, oldValue);
}
}
@ -71,19 +69,43 @@ export default class DropDown {
});
}
_setFocusInFilterInput(value, oldValue) {
if (value && !this._focusingFilter && oldValue !== value && this.filter) {
this.$timeout(() => {
let inputFilterSearch = this.$element[0].querySelector('input');
this._focusingFilter = true;
if (inputFilterSearch)
this.$timeout(() => {
inputFilterSearch.focus();
this._focusingFilter = false;
}, 250);
_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) {
this.$timeout(() => {
let inputFilterSearch = this.$element[0].querySelector('input');
this._focusingFilter = true;
if (inputFilterSearch)
this.$timeout(() => {
inputFilterSearch.focus();
this._focusingFilter = false;
}, 250);
});
}
_background(create) {
let el = document.getElementById('ddBack');
if (el) {
@ -230,14 +252,10 @@ export default class DropDown {
$onInit() {
if (this.parent)
this.parent.addEventListener('keydown', e => this.onKeydown(e));
if (this.container)
this.container.addEventListener('scroll', e => this.loadFromScroll(e));
}
$onDestroy() {
if (this.parent)
this.parent.removeEventListener('keydown', e => this.onKeydown(e));
if (this.container)
this.container.removeEventListener('scroll', e => this.loadFromScroll(e));
}
}