aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/ContextMenu.tsx
diff options
context:
space:
mode:
authormehekj <mehek.jethani@gmail.com>2022-10-12 13:21:07 -0400
committermehekj <mehek.jethani@gmail.com>2022-10-12 13:21:07 -0400
commit0b3a83acd4f75b7f6ff4b9bb7daf4377dede51a1 (patch)
tree438789f7e7f50e5eb9829e1f301b4d043d8d4906 /src/client/views/ContextMenu.tsx
parent69ca9baca6ff1da272a5191187542351bd242ccc (diff)
parenteb5f75785fd28acb50f1b30434e89223fff00185 (diff)
Merge branch 'master' into schema-mehek
Diffstat (limited to 'src/client/views/ContextMenu.tsx')
-rw-r--r--src/client/views/ContextMenu.tsx30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/client/views/ContextMenu.tsx b/src/client/views/ContextMenu.tsx
index c9908b4b0..6a530e3ae 100644
--- a/src/client/views/ContextMenu.tsx
+++ b/src/client/views/ContextMenu.tsx
@@ -118,27 +118,11 @@ export class ContextMenu extends React.Component {
static readonly buffer = 20;
get pageX() {
- const x = this._pageX;
- if (x < 0) {
- return 0;
- }
- const width = this._width;
- if (x + width > window.innerWidth - ContextMenu.buffer) {
- return window.innerWidth - ContextMenu.buffer - width;
- }
- return x;
+ return this._pageX + this._width > window.innerWidth - ContextMenu.buffer ? window.innerWidth - ContextMenu.buffer - this._width : Math.max(0, this._pageX);
}
get pageY() {
- const y = this._pageY;
- if (y < 0) {
- return 0;
- }
- const height = this._height;
- if (y + height > window.innerHeight - ContextMenu.buffer) {
- return window.innerHeight - ContextMenu.buffer - height;
- }
- return y;
+ return this._pageY + this._height > window.innerHeight - ContextMenu.buffer ? window.innerHeight - ContextMenu.buffer - this._height : Math.max(0, this._pageY);
}
_onDisplay?: () => void = undefined;
@@ -223,7 +207,15 @@ export class ContextMenu extends React.Component {
render() {
return !this._display ? null : (
- <div className="contextMenu-cont" style={{ left: this.pageX, ...(this._yRelativeToTop ? { top: this.pageY } : { bottom: this.pageY }) }}>
+ <div
+ className="contextMenu-cont"
+ ref={action((r: any) => {
+ if (r) {
+ this._width = Number(getComputedStyle(r).width.replace('px', ''));
+ this._height = Number(getComputedStyle(r).height.replace('px', ''));
+ }
+ })}
+ style={{ left: this.pageX, ...(this._yRelativeToTop ? { top: this.pageY } : { bottom: this.pageY }) }}>
{!this.itemsNeedSearch ? null : (
<span className={'search-icon'}>
<span className="icon-background">