nuevo refactor a dropDown

This commit is contained in:
Daniel Herrero 2017-12-12 14:14:32 +01:00
parent 5c54550283
commit 7f0dc42500
1 changed files with 15 additions and 17 deletions

View File

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