refactoring de dropDown, ya no watchea si no está abierto

This commit is contained in:
Daniel Herrero 2017-12-12 13:38:23 +01:00
parent 34016dfa1e
commit 6d1bbfe6c2
2 changed files with 19 additions and 11 deletions

View File

@ -1,4 +1,4 @@
<vn-vertical class="dropdown-body" ng-show="$ctrl.show">
<vn-vertical class="dropdown-body" ng-if="$ctrl.show">
<vn-auto ng-show="$ctrl.filter" class="filter">
<vn-horizontal>
<input vn-one placeholder="{{'Search' | translate}}" type="text" ng-model="$ctrl.search"/>

View File

@ -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) {