From 7f0dc42500dc420cf9bbcc109c08e25253c4bbb0 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Tue, 12 Dec 2017 14:14:32 +0100 Subject: [PATCH] nuevo refactor a dropDown --- client/core/src/drop-down/drop-down.js | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/client/core/src/drop-down/drop-down.js b/client/core/src/drop-down/drop-down.js index 8874cb592..deaea7743 100644 --- a/client/core/src/drop-down/drop-down.js +++ b/client/core/src/drop-down/drop-down.js @@ -24,7 +24,7 @@ export default class DropDown { set show(value) { let oldValue = this.show; - // I wait up to 1 second if the dropdown opens but there is no data to show + // It wait up to 1 second if the dropdown opens but there is no data to show if (value && !oldValue && !this.itemsFiltered.length && this._tryToShow < 4) { this.$timeout(() => { this._tryToShow++; @@ -72,11 +72,13 @@ export default class DropDown { _toggleDropDown(value, oldValue) { if (value && !this._focusingFilter && !oldValue && this.filter) { // open dropDown - this._setFocusInFilterInput(); - this._eventScroll(true); + this.$timeout(() => { // wait angular ngIf + this._setFocusInFilterInput(); + this._eventScroll(value); + }); } else if (!value && oldValue) { // close dropDown - this._eventScroll(false); + this._eventScroll(value); } this.$timeout(() => { @@ -86,24 +88,20 @@ export default class DropDown { _eventScroll(add) { if (add) { - this.$timeout(() => { // wait angular ngIf - this.container.addEventListener('scroll', e => this.loadFromScroll(e)); - }); + 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); - }); + _setFocusInFilterInput() { + let inputFilterSearch = this.$element[0].querySelector('input'); + this._focusingFilter = true; + if (inputFilterSearch) + this.$timeout(() => { + inputFilterSearch.focus(); + this._focusingFilter = false; + }, 250); } _background(create) {