Refactor #500 - For OverlayPanel

pull/525/head
mertsincan 2020-09-27 19:53:38 +03:00
parent 1c89ad4aa2
commit ee5f43f753
1 changed files with 30 additions and 1 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<transition name="p-overlaypanel" @enter="onEnter" @leave="onLeave"> <transition name="p-overlaypanel" @enter="onEnter" @leave="onLeave">
<div class="p-overlaypanel p-component" v-if="visible" :ref="containerRef"> <div class="p-overlaypanel p-component" v-if="visible" :id="containerId" :ref="containerRef">
<div class="p-overlaypanel-content"> <div class="p-overlaypanel-content">
<slot></slot> <slot></slot>
</div> </div>
@ -12,11 +12,14 @@
</template> </template>
<script> <script>
import ConnectedOverlayScrollHandler from '../utils/ConnectedOverlayScrollHandler';
import UniqueComponentId from '../utils/UniqueComponentId';
import DomHandler from '../utils/DomHandler'; import DomHandler from '../utils/DomHandler';
import Ripple from '../ripple/Ripple'; import Ripple from '../ripple/Ripple';
export default { export default {
props: { props: {
id: null,
dismissable: { dismissable: {
type: Boolean, type: Boolean,
default: true default: true
@ -49,6 +52,7 @@ export default {
}, },
target: null, target: null,
outsideClickListener: null, outsideClickListener: null,
scrollHandler: null,
resizeListener: null, resizeListener: null,
container: null, container: null,
beforeUnmount() { beforeUnmount() {
@ -57,6 +61,8 @@ export default {
if (this.dismissable) { if (this.dismissable) {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
} }
this.unbindScrollListener();
this.scrollHandler = null;
this.target = null; this.target = null;
this.container = null; this.container = null;
}, },
@ -82,6 +88,7 @@ export default {
} }
this.bindResizeListener(); this.bindResizeListener();
this.bindScrollListener();
if (this.autoZIndex) { if (this.autoZIndex) {
this.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex()); this.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
@ -90,6 +97,7 @@ export default {
onLeave() { onLeave() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindResizeListener(); this.unbindResizeListener();
this.unbindScrollListener();
}, },
alignOverlay() { alignOverlay() {
DomHandler.absolutePosition(this.container, this.target); DomHandler.absolutePosition(this.container, this.target);
@ -114,6 +122,22 @@ export default {
this.outsideClickListener = null; this.outsideClickListener = null;
} }
}, },
bindScrollListener() {
if (!this.scrollHandler) {
this.scrollHandler = new ConnectedOverlayScrollHandler(this.target, this.containerId, () => {
if (this.visible) {
this.visible = false;
}
});
}
this.scrollHandler.bindScrollListener();
},
unbindScrollListener() {
if (this.scrollHandler) {
this.scrollHandler.unbindScrollListener();
}
},
bindResizeListener() { bindResizeListener() {
if (!this.resizeListener) { if (!this.resizeListener) {
this.resizeListener = () => { this.resizeListener = () => {
@ -153,6 +177,11 @@ export default {
this.container = el; this.container = el;
} }
}, },
computed: {
containerId() {
return this.id || UniqueComponentId();
}
},
directives: { directives: {
'ripple': Ripple 'ripple': Ripple
} }