From ddd66d8fe268c082e96d97d2b2f4618cb494a214 Mon Sep 17 00:00:00 2001 From: leorolland Date: Thu, 16 Jun 2022 22:51:50 +0200 Subject: [PATCH] fix(placement): scroll Y axis menu offset --- ContextMenu.js | 5 +++-- index.js | 6 ++++-- package.json | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ContextMenu.js b/ContextMenu.js index b5c3bef..5e36b86 100644 --- a/ContextMenu.js +++ b/ContextMenu.js @@ -156,8 +156,9 @@ function useContextMenu(props = {}) { left = windowWidth - menuWidth; } - if (top + menuHeight > windowHeight) { - top = windowHeight - menuHeight; + const screenBottom = window.pageYOffset + windowHeight; + if (top + menuHeight > screenBottom) { + top = screenBottom - menuHeight; } return { left, top }; diff --git a/index.js b/index.js index c0911f7..7d247e3 100644 --- a/index.js +++ b/index.js @@ -241,8 +241,10 @@ function useContextMenu() { left = windowWidth - menuWidth; } - if (top + menuHeight > windowHeight) { - top = windowHeight - menuHeight; + var screenBottom = window.pageYOffset + windowHeight; + + if (top + menuHeight > screenBottom) { + top = screenBottom - menuHeight; } return { diff --git a/package.json b/package.json index f6e475b..5b680c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contextmenu", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "eslintConfig": { "extends": "react-app"