mirror of https://github.com/Fabio286/antares.git
fix: context menu outside window when near bottom or right edge
This commit is contained in:
parent
27d114beef
commit
d4ecaf65e5
|
@ -6,6 +6,7 @@
|
||||||
@contextmenu="close"
|
@contextmenu="close"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
|
ref="contextContent"
|
||||||
class="context-container"
|
class="context-container"
|
||||||
:style="position"
|
:style="position"
|
||||||
>
|
>
|
||||||
|
@ -20,17 +21,37 @@ export default {
|
||||||
props: {
|
props: {
|
||||||
contextEvent: MouseEvent
|
contextEvent: MouseEvent
|
||||||
},
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
contextSize: null
|
||||||
|
};
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
position () {
|
position () {
|
||||||
return { // TODO: calc direction if near corners
|
const { clientY, clientX } = this.contextEvent;
|
||||||
top: this.contextEvent.clientY + 5 + 'px',
|
let topCord = `${clientY + 5}px`;
|
||||||
left: this.contextEvent.clientX + 5 + 'px'
|
let leftCord = `${clientX + 5}px`;
|
||||||
|
|
||||||
|
if (this.contextSize) {
|
||||||
|
if (clientY + this.contextSize.height + 5 >= window.innerHeight)
|
||||||
|
topCord = `${clientY - this.contextSize.height}px`;
|
||||||
|
|
||||||
|
if (clientX + this.contextSize.width + 5 >= window.innerWidth)
|
||||||
|
leftCord = `${clientX - this.contextSize.width}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: topCord,
|
||||||
|
left: leftCord
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
window.addEventListener('keydown', this.onKey);
|
window.addEventListener('keydown', this.onKey);
|
||||||
},
|
},
|
||||||
|
mounted () {
|
||||||
|
this.contextSize = this.$refs.contextContent.getBoundingClientRect();
|
||||||
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
window.removeEventListener('keydown', this.onKey);
|
window.removeEventListener('keydown', this.onKey);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue