Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 212ce3e

Browse files
author
Andreas Creten
authored
Correct position of the menu when out of viewport
When a context menu is higher than the place above the coordinates you clicked it would go outside of the viewport at the top of the screen. This PR makes it so that it will appear central in on the screen in that case. If the menu is higher than the viewport it will stick to the top of the screen. Applied the same logic to the horizontal axis.
1 parent 6f4f1c6 commit 212ce3e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/context-menu/wrapper.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ let ContextMenuWrapper = React.createClass({
6464
if (x + rect.width > innerWidth) {
6565
menuStyles.left -= rect.width;
6666
}
67+
68+
if (menuStyles.top < 0) {
69+
menuStyles.top = (rect.height < innerHeight) ? (innerHeight - rect.height) / 2 : 0;
70+
}
71+
72+
if (menuStyles.left < 0) {
73+
menuStyles.left = (rect.width < innerWidth) ? (innerWidth - rect.width) / 2 : 0;
74+
}
6775

6876
return menuStyles;
6977
},

0 commit comments

Comments
 (0)