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,19 +69,43 @@ export default class DropDown {
}); });
} }
_setFocusInFilterInput(value, oldValue) { _toggleDropDown(value, oldValue) {
if (value && !this._focusingFilter && oldValue !== value && this.filter) { if (value && !this._focusingFilter && !oldValue && this.filter) {
this.$timeout(() => { // open dropDown
let inputFilterSearch = this.$element[0].querySelector('input'); this._setFocusInFilterInput();
this._focusingFilter = true; this._eventScroll(true);
if (inputFilterSearch) } else if (!value && oldValue) {
this.$timeout(() => { // close dropDown
inputFilterSearch.focus(); this._eventScroll(false);
this._focusingFilter = false; }
}, 250);
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) { _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));
} }
} }