Fixed #289 - SplitButton is misaligned

pull/310/head
cagataycivici 2020-04-23 09:28:51 +03:00
parent 3102658b40
commit 6032170092
2 changed files with 17 additions and 3 deletions

View File

@ -51,6 +51,7 @@ export default {
target: null, target: null,
outsideClickListener: null, outsideClickListener: null,
resizeListener: null, resizeListener: null,
relativeAlign: false,
beforeDestroy() { beforeDestroy() {
this.restoreAppend(); this.restoreAppend();
this.unbindResizeListener(); this.unbindResizeListener();
@ -78,10 +79,13 @@ export default {
}, },
show(event) { show(event) {
this.visible = true; this.visible = true;
this.relativeAlign = event.relativeAlign;
this.target = event.currentTarget; this.target = event.currentTarget;
}, },
hide() { hide() {
this.visible = false; this.visible = false;
this.target = false;
this.relativeAlign = false;
}, },
onEnter() { onEnter() {
this.appendContainer(); this.appendContainer();
@ -98,7 +102,11 @@ export default {
this.unbindResizeListener(); this.unbindResizeListener();
}, },
alignOverlay() { alignOverlay() {
DomHandler.absolutePosition(this.$refs.container, this.target); if (this.relativeAlign)
DomHandler.relativePosition(this.$refs.container, this.target);
else
DomHandler.absolutePosition(this.$refs.container, this.target);
}, },
bindOutsideClickListener() { bindOutsideClickListener() {
if (!this.outsideClickListener) { if (!this.outsideClickListener) {
@ -150,6 +158,12 @@ export default {
else else
document.getElementById(this.appendTo).removeChild(this.$refs.container); document.getElementById(this.appendTo).removeChild(this.$refs.container);
} }
},
beforeDestroy() {
this.restoreAppend();
this.unbindResizeListener();
this.unbindOutsideClickListener();
this.target = null;
} }
}, },
computed: { computed: {

View File

@ -4,7 +4,7 @@
<PVSButton type="button" class="p-splitbutton-menubutton" icon="pi pi-caret-down" @click="onDropdownButtonClick" :disabled="disabled" <PVSButton type="button" class="p-splitbutton-menubutton" icon="pi pi-caret-down" @click="onDropdownButtonClick" :disabled="disabled"
aria-haspopup="true" :aria-controls="ariaId + '_overlay'"/> aria-haspopup="true" :aria-controls="ariaId + '_overlay'"/>
<PVSMenu :id="ariaId + '_overlay'" ref="menu" :model="model" :popup="true" :autoZIndex="autoZIndex" <PVSMenu :id="ariaId + '_overlay'" ref="menu" :model="model" :popup="true" :autoZIndex="autoZIndex"
:baseZIndex="baseZIndex" :appendTo="appendTo"/> :baseZIndex="baseZIndex" :appendTo="appendTo" />
</div> </div>
</template> </template>
@ -53,7 +53,7 @@ export default {
this.$emit('click', event); this.$emit('click', event);
}, },
onDropdownButtonClick() { onDropdownButtonClick() {
this.$refs.menu.toggle({currentTarget: this.$el}); this.$refs.menu.toggle({currentTarget: this.$el, relativeAlign: this.appendTo == null});
} }
}, },
computed: { computed: {