mirror of
				https://github.com/Fabio286/antares.git
				synced 2025-06-05 21:59:22 +02:00 
			
		
		
		
	fix: context menu outside window when near bottom or right edge
This commit is contained in:
		| @@ -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); | ||||||
|    }, |    }, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user