refactoring de dropDown, ya no watchea si no está abierto
This commit is contained in:
parent
34016dfa1e
commit
6d1bbfe6c2
|
@ -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"/>
|
||||
|
|
|
@ -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) {
|
||||
this.$timeout(() => {
|
||||
let inputFilterSearch = this.$element[0].querySelector('input');
|
||||
this._focusingFilter = true;
|
||||
if (inputFilterSearch)
|
||||
this.$timeout(() => {
|
||||
inputFilterSearch.focus();
|
||||
this._focusingFilter = false;
|
||||
}, 250);
|
||||
});
|
||||
}
|
||||
}
|
||||
_background(create) {
|
||||
|
@ -184,12 +190,14 @@ export default class DropDown {
|
|||
}
|
||||
setScrollPosition() {
|
||||
let child = this.$element[0].querySelector('ul.dropdown li.active');
|
||||
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) {
|
||||
this.selected = item;
|
||||
if (this.multiple) {
|
||||
|
|
Loading…
Reference in New Issue