Refactor #4820
parent
d5742af12c
commit
23065b97d9
|
@ -61,6 +61,7 @@ export default {
|
||||||
name: 'Menubar',
|
name: 'Menubar',
|
||||||
extends: BaseMenubar,
|
extends: BaseMenubar,
|
||||||
emits: ['focus', 'blur'],
|
emits: ['focus', 'blur'],
|
||||||
|
matchMediaListener: null,
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
id: this.$attrs.id,
|
id: this.$attrs.id,
|
||||||
|
@ -69,6 +70,7 @@ export default {
|
||||||
focusedItemInfo: { index: -1, level: 0, parentKey: '' },
|
focusedItemInfo: { index: -1, level: 0, parentKey: '' },
|
||||||
activeItemPath: [],
|
activeItemPath: [],
|
||||||
dirty: false,
|
dirty: false,
|
||||||
|
query: null,
|
||||||
queryMatches: false
|
queryMatches: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -91,19 +93,13 @@ export default {
|
||||||
menubar: null,
|
menubar: null,
|
||||||
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();
|
||||||
|
|
||||||
if (this.container) {
|
if (this.container) {
|
||||||
ZIndexUtils.clear(this.container);
|
ZIndexUtils.clear(this.container);
|
||||||
|
@ -462,6 +458,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