Skip to content

Commit

Permalink
Refactor #500 - For Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Sep 27, 2020
1 parent b5522c4 commit 300e278
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/components/menu/Menu.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<transition name="p-connected-overlay" @enter="onEnter" @leave="onLeave">
<div :ref="containerRef" :class="containerClass" v-if="popup ? overlayVisible : true">
<div :ref="containerRef" :id="containerId" :class="containerClass" v-if="popup ? overlayVisible : true">
<ul class="p-menu-list p-reset" role="menu">
<template v-for="(item, i) of model">
<template v-if="item.items && visible(item) && !item.separator">
Expand All @@ -19,11 +19,14 @@
</template>

<script>
import ConnectedOverlayScrollHandler from '../utils/ConnectedOverlayScrollHandler';
import UniqueComponentId from '../utils/UniqueComponentId';
import DomHandler from '../utils/DomHandler';
import Menuitem from './Menuitem';
export default {
props: {
id: null,
popup: {
type: Boolean,
default: false
Expand Down Expand Up @@ -52,13 +55,16 @@ export default {
},
target: null,
outsideClickListener: null,
scrollHandler: null,
resizeListener: null,
relativeAlign: false,
container: null,
beforeUnmount() {
this.restoreAppend();
this.unbindResizeListener();
this.unbindOutsideClickListener();
this.unbindScrollListener();
this.scrollHandler = null;
this.target = null;
},
methods: {
Expand Down Expand Up @@ -87,14 +93,15 @@ export default {
},
hide() {
this.overlayVisible = false;
this.target = false;
this.target = null;
this.relativeAlign = false;
},
onEnter() {
this.appendContainer();
this.alignOverlay();
this.bindOutsideClickListener();
this.bindResizeListener();
this.bindScrollListener();
if (this.autoZIndex) {
this.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
Expand All @@ -103,6 +110,7 @@ export default {
onLeave() {
this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindScrollListener();
},
alignOverlay() {
if (this.relativeAlign)
Expand All @@ -127,6 +135,22 @@ export default {
this.outsideClickListener = null;
}
},
bindScrollListener() {
if (!this.scrollHandler) {
this.scrollHandler = new ConnectedOverlayScrollHandler(this.target, this.containerId, () => {
if (this.overlayVisible) {
this.hide();
}
});
}
this.scrollHandler.bindScrollListener();
},
unbindScrollListener() {
if (this.scrollHandler) {
this.scrollHandler.unbindScrollListener();
}
},
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = () => {
Expand Down Expand Up @@ -166,6 +190,8 @@ export default {
this.restoreAppend();
this.unbindResizeListener();
this.unbindOutsideClickListener();
this.unbindScrollListener();
this.scrollHandler = null;
this.target = null;
this.container = null;
},
Expand All @@ -177,6 +203,9 @@ export default {
}
},
computed: {
containerId() {
return this.id || UniqueComponentId();
},
containerClass() {
return ['p-menu p-component', {
'p-menu-overlay': this.popup
Expand Down

0 comments on commit 300e278

Please sign in to comment.