diff --git a/client/core/src/drop-down/drop-down.js b/client/core/src/drop-down/drop-down.js index ac99fe7d2..8874cb592 100644 --- a/client/core/src/drop-down/drop-down.js +++ b/client/core/src/drop-down/drop-down.js @@ -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)); } }