Refactor #4819
parent
4092e43465
commit
1aff573453
|
@ -65,6 +65,7 @@ export default {
|
||||||
emits: ['focus', 'blur'],
|
emits: ['focus', 'blur'],
|
||||||
outsideClickListener: null,
|
outsideClickListener: null,
|
||||||
resizeListener: null,
|
resizeListener: null,
|
||||||
|
matchMediaListener: null,
|
||||||
container: null,
|
container: null,
|
||||||
menubar: null,
|
menubar: null,
|
||||||
searchTimeout: null,
|
searchTimeout: null,
|
||||||
|
@ -77,6 +78,7 @@ export default {
|
||||||
focusedItemInfo: { index: -1, key: '', parentKey: '' },
|
focusedItemInfo: { index: -1, key: '', parentKey: '' },
|
||||||
activeItem: null,
|
activeItem: null,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
|
query: null,
|
||||||
queryMatches: false
|
queryMatches: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -96,19 +98,13 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.id = this.id || UniqueComponentId();
|
this.id = this.id || UniqueComponentId();
|
||||||
const query = matchMedia(`(max-width: ${this.breakpoint})`);
|
this.bindMatchMediaListener();
|
||||||
|
|
||||||
this.queryMatches = query.matches;
|
|
||||||
|
|
||||||
query.addEventListener('change', () => {
|
|
||||||
this.queryMatches = query.matches;
|
|
||||||
this.mobileActive = false;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
this.mobileActive = false;
|
this.mobileActive = false;
|
||||||
this.unbindOutsideClickListener();
|
this.unbindOutsideClickListener();
|
||||||
this.unbindResizeListener();
|
this.unbindResizeListener();
|
||||||
|
this.unbindMatchMediaListener();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getItemProp(item, name) {
|
getItemProp(item, name) {
|
||||||
|
@ -490,6 +486,27 @@ export default {
|
||||||
this.resizeListener = null;
|
this.resizeListener = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
bindMatchMediaListener() {
|
||||||
|
if (!this.matchMediaListener) {
|
||||||
|
const query = matchMedia(`(max-width: ${this.breakpoint})`);
|
||||||
|
|
||||||
|
this.query = query;
|
||||||
|
this.queryMatches = query.matches;
|
||||||
|
|
||||||
|
this.matchMediaListener = () => {
|
||||||
|
this.queryMatches = query.matches;
|
||||||
|
this.mobileActive = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.query.addEventListener('change', this.matchMediaListener);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
unbindMatchMediaListener() {
|
||||||
|
if (this.matchMediaListener) {
|
||||||
|
this.query.removeEventListener('change', this.matchMediaListener);
|
||||||
|
this.matchMediaListener = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
isItemMatched(processedItem) {
|
isItemMatched(processedItem) {
|
||||||
return this.isValidItem(processedItem) && this.getProccessedItemLabel(processedItem).toLocaleLowerCase().startsWith(this.searchValue.toLocaleLowerCase());
|
return this.isValidItem(processedItem) && this.getProccessedItemLabel(processedItem).toLocaleLowerCase().startsWith(this.searchValue.toLocaleLowerCase());
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue