diff --git a/components/lib/calendar/Calendar.vue b/components/lib/calendar/Calendar.vue index 52d89acbe..45288d790 100755 --- a/components/lib/calendar/Calendar.vue +++ b/components/lib/calendar/Calendar.vue @@ -520,6 +520,7 @@ export default { outsideClickListener: null, maskClickListener: null, resizeListener: null, + matchMediaListener: null, overlay: null, input: null, mask: null, @@ -539,6 +540,7 @@ export default { focused: false, overlayVisible: false, currentView: this.view, + query: null, queryMatches: false }; }, @@ -589,13 +591,7 @@ export default { }, mounted() { this.createResponsiveStyle(); - const query = matchMedia(`(max-width: ${this.breakpoint})`); - - this.queryMatches = query.matches; - - query.addEventListener('change', () => { - this.queryMatches = query.matches; - }); + this.bindMatchMediaListener(); if (this.inline) { this.overlay && this.overlay.setAttribute(this.attributeSelector, ''); @@ -638,6 +634,7 @@ export default { this.unbindOutsideClickListener(); this.unbindResizeListener(); + this.unbindMatchMediaListener(); if (this.scrollHandler) { this.scrollHandler.destroy(); @@ -1022,6 +1019,27 @@ export default { 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; + } + }, isOutsideClicked(event) { return !(this.$el.isSameNode(event.target) || this.isNavIconClicked(event) || this.$el.contains(event.target) || (this.overlay && this.overlay.contains(event.target))); },