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"