From 6d1bbfe6c22dc796492687f5287da86611aed7a5 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Tue, 12 Dec 2017 13:38:23 +0100 Subject: [PATCH] =?UTF-8?q?refactoring=20de=20dropDown,=20ya=20no=20watche?= =?UTF-8?q?a=20si=20no=20est=C3=A1=20abierto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/core/src/drop-down/drop-down.html | 2 +- client/core/src/drop-down/drop-down.js | 28 +++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/client/core/src/drop-down/drop-down.html b/client/core/src/drop-down/drop-down.html index 04cdffc75..c8971a551 100644 --- a/client/core/src/drop-down/drop-down.html +++ b/client/core/src/drop-down/drop-down.html @@ -1,4 +1,4 @@ - + diff --git a/client/core/src/drop-down/drop-down.js b/client/core/src/drop-down/drop-down.js index e8227858a..ac99fe7d2 100644 --- a/client/core/src/drop-down/drop-down.js +++ b/client/core/src/drop-down/drop-down.js @@ -7,13 +7,16 @@ export default class DropDown { this.$filter = $filter; this.$timeout = $timeout; - this.container = $element[0].querySelector('ul.dropdown'); this._search = null; this.itemsFiltered = []; this._activeOption = -1; this._focusingFilter = false; this._tryToShow = 0; } + + get container() { + return this.$element[0].querySelector('ul.dropdown'); + } get show() { return this._show; } @@ -70,12 +73,15 @@ export default class DropDown { _setFocusInFilterInput(value, oldValue) { if (value && !this._focusingFilter && oldValue !== value && this.filter) { - let inputFilterSearch = this.$element[0].querySelector('input'); - this._focusingFilter = true; this.$timeout(() => { - inputFilterSearch.focus(); - this._focusingFilter = false; - }, 250); + let inputFilterSearch = this.$element[0].querySelector('input'); + this._focusingFilter = true; + if (inputFilterSearch) + this.$timeout(() => { + inputFilterSearch.focus(); + this._focusingFilter = false; + }, 250); + }); } } _background(create) { @@ -184,10 +190,12 @@ export default class DropDown { } setScrollPosition() { let child = this.$element[0].querySelector('ul.dropdown li.active'); - let childRect = child.getBoundingClientRect(); - let containerRect = this.container.getBoundingClientRect(); - if (typeof child.scrollIntoView === 'function' && (childRect.top > containerRect.top + containerRect.height || childRect.top < containerRect.top)) { - child.scrollIntoView(); + if (child) { + let childRect = child.getBoundingClientRect(); + let containerRect = this.container.getBoundingClientRect(); + if (typeof child.scrollIntoView === 'function' && (childRect.top > containerRect.top + containerRect.height || childRect.top < containerRect.top)) { + child.scrollIntoView(); + } } } selectItem(item) {