From 00bd4a7696c1f82bce8e0f81f10d43f357577b62 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Thu, 23 Nov 2017 14:07:55 +0100 Subject: [PATCH] nuevo comportamiento para dropDown, abrir arriba --- client/core/src/drop-down/drop-down.html | 8 ++-- client/core/src/drop-down/drop-down.js | 57 +++++++++++++++++------- client/core/src/drop-down/style.scss | 24 +++++++++- 3 files changed, 69 insertions(+), 20 deletions(-) diff --git a/client/core/src/drop-down/drop-down.html b/client/core/src/drop-down/drop-down.html index 9bab06069..04cdffc75 100644 --- a/client/core/src/drop-down/drop-down.html +++ b/client/core/src/drop-down/drop-down.html @@ -1,11 +1,11 @@ - + - - + + - + \ No newline at end of file diff --git a/client/core/src/drop-down/drop-down.js b/client/core/src/drop-down/drop-down.js index f34e44e89..e8227858a 100644 --- a/client/core/src/drop-down/drop-down.js +++ b/client/core/src/drop-down/drop-down.js @@ -12,6 +12,7 @@ export default class DropDown { this.itemsFiltered = []; this._activeOption = -1; this._focusingFilter = false; + this._tryToShow = 0; } get show() { return this._show; @@ -19,11 +20,20 @@ export default class DropDown { set show(value) { let oldValue = this.show; - this._show = value; - this._setFocusInFilterInput(value, oldValue); - this.$timeout(() => { - this._calculatePosition(value, oldValue); - }); + // I 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++; + this.show = true; + }, 250); + } else { + this._tryToShow = 0; + this._show = value; + this._setFocusInFilterInput(value, oldValue); + this.$timeout(() => { + this._calculatePosition(value, oldValue); + }); + } } get search() { @@ -68,21 +78,42 @@ export default class DropDown { }, 250); } } + _background(create) { + let el = document.getElementById('ddBack'); + if (el) { + el.parentNode.removeChild(el); + } + + if (create) { + el = document.createElement('div'); + el.id = 'ddBack'; + document.body.appendChild(el); + } + } _calculatePosition(value, oldValue) { - if (value && value !== oldValue && !this.top) { + if (value && !oldValue) { if (this.parent === undefined) { this.parent = this.$element.parent().parent(); } let parentRect = this.parent.getBoundingClientRect(); let elemetRect = this.$element[0].getBoundingClientRect(); + let instOffset = parentRect.bottom + elemetRect.height; - if (parentRect.y + parentRect.height + elemetRect.height > window.innerHeight) { - let height = this.parent.nodeName === 'VN-AUTOCOMPLETE' ? elemetRect.height : elemetRect.height + parentRect.height; - this.$element.css('margin-top', `-${height}px`); - } else { - this.$element.css('margin-top', ``); + if (instOffset >= window.innerHeight) { + this._background(true); + this.$element.addClass('fixed-dropDown'); + this.$element.css('top', `${(parentRect.top - elemetRect.height)}px`); + this.$element.css('left', `${(parentRect.x)}px`); + this.$element.css('height', `${elemetRect.height}px`); } + } else if (!value && oldValue) { + this.$element.removeAttr('style'); + if (this.itemWidth) { + this.$element.css('width', this.itemWidth + 'px'); + } + this.$element.removeClass('fixed-dropDown'); + this._background(); } } @@ -181,9 +212,6 @@ export default class DropDown { } } $onChanges(changesObj) { - if (changesObj.show && changesObj.top && changesObj.top.currentValue) { - this.$element.css('top', changesObj.top.currentValue + 'px'); - } if (changesObj.show && changesObj.itemWidth && changesObj.itemWidth.currentValue) { this.$element.css('width', changesObj.itemWidth.currentValue + 'px'); } @@ -220,7 +248,6 @@ module.component('vnDropDown', { removeLoadMore: '