react-contexify icon indicating copy to clipboard operation
react-contexify copied to clipboard

Not able to view submenu when context menu is opened at right edge of screen

Open rajutanniru44 opened this issue 7 years ago • 4 comments

when we open the context menu in right side area of screen in the browser, submenu is not visible . it is rendered, but not visible on the screen.

i have a solution for that

Solution: when context menu is opened ,other than right side area of browser, the below css is applied.

left: 100%; bottom: 0px; top: initial;

when we open context menu on right side, below css is applied

left: 100%; bottom: 0px; top: initial; right:100%;

so, the submenu should be visible on left side of main menu, but it is not visible because the left property of css.

remove the left:100% property css or make it null in Submenu.js file while comparing the screen width and object width in componentDidMount method.

please fix this,If my solution is not correct, would any one else share the solution for this issue.

rajutanniru44 avatar Dec 24 '18 10:12 rajutanniru44

Submenu.prototype.componentDidMount = function () { var innerWidth = window.innerWidth, innerHeight = window.innerHeight; var rect = this.menu.getBoundingClientRect(); var style = {};

if (rect.right < innerWidth) {
   style.left = '100%';
   style.right = null;
} else {
   style.right = '100%';
   style.left =null;
}

if (rect.bottom > innerHeight) {
  style.bottom = 0;
  style.top = 'initial';
} else {
  style.bottom = 'initial';
  style.top = 0;
}

this.setState(style);

};

replace the above code in submenu.js file , it might fix the issue

RajuIO avatar Dec 24 '18 13:12 RajuIO

Hello,

The issue is fixed with the release v4.0.1. Thanks for reporting the issue.

fkhadra avatar Dec 31 '18 09:12 fkhadra

thanks for fixing the issue

RajuIO avatar Dec 31 '18 09:12 RajuIO

Hi all! This bug remains. When a dropdown opens on the right side, but its right side is not pressed against the edge of the browser window, the following styles are applied:

style.left` = '100%';
style.right = undefined;

Because of this, the submenu goes beyond the browser window. I suggest to implement the following logic:

useEffect(() => {
    if (nodeRef.current) {
      const { innerWidth, innerHeight } = window;
      const rect = nodeRef.current.getBoundingClientRect();
      const style: SubMenuState = {};

      if (rect.right < (innerWidth - innerWidth / 3)) {
        style.left = '100%';
        style.right = undefined;
      } else {
        style.right = '100%';
        style.left = undefined;
      }

      if (rect.bottom > innerHeight) {
        style.bottom = 0;
        style.top = 'initial';
      } else {
        style.bottom = 'initial';
        style.top = 0;
      }

      setPosition(style);
    }
  }, []);

I think it can fix this bug. Thanks

roildev avatar Oct 03 '22 09:10 roildev