appendTo option for OverlayPanel

pull/12/head
cagataycivici 2019-02-03 21:34:25 +03:00
parent 10ba7e4da1
commit 9e97b24882
2 changed files with 20 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import DomHandler from '../utils/DomHandler';
export default { export default {
props: { props: {
appendTo: String,
baseZIndex: { baseZIndex: {
type: Number, type: Number,
default: 0 default: 0
@ -30,6 +31,7 @@ export default {
target: null, target: null,
outsideClickListener: null, outsideClickListener: null,
beforeDestroy() { beforeDestroy() {
this.restoreAppend();
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.target = null; this.target = null;
}, },
@ -48,6 +50,7 @@ export default {
this.visible = false; this.visible = false;
}, },
onEnter() { onEnter() {
this.appendContainer();
this.alignOverlay(); this.alignOverlay();
this.bindOutsideClickListener(); this.bindOutsideClickListener();
@ -79,6 +82,22 @@ export default {
}, },
isTargetClicked() { isTargetClicked() {
return this.target && (this.target === event.target || this.target.contains(event.target)); return this.target && (this.target === event.target || this.target.contains(event.target));
},
appendContainer() {
if (this.appendTo) {
if (this.appendTo === 'body')
document.body.appendChild(this.$refs.container);
else
document.getElementById(this.appendTo).appendChild(this.$refs.container);
}
},
restoreAppend() {
if (this.$refs.container && this.appendTo) {
if (this.appendTo === 'body')
document.body.removeChild(this.$refs.container);
else
document.getElementById(this.appendTo).removeChild(this.$refs.container);
}
} }
} }
} }

View File

@ -10,7 +10,7 @@
<div class="content-section implementation"> <div class="content-section implementation">
<Button type="button" label="Toggle" @click="toggle" /> <Button type="button" label="Toggle" @click="toggle" />
<OverlayPanel ref="op"> <OverlayPanel ref="op" appendTo="body">
<img src="/demo/images/nature/nature1.jpg" alt="Nature Image"> <img src="/demo/images/nature/nature1.jpg" alt="Nature Image">
</OverlayPanel> </OverlayPanel>
</div> </div>