Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat: make context menu scrollable (#4030)

Shubham Shah958ebeae61f8
diff --git a/src/components/Popover.scss b/src/components/Popover.scss
index 594d44e29c..84d16e47f6 100644
--- a/src/components/Popover.scss
+++ b/src/components/Popover.scss
@@ -2,5 +2,6 @@
.popover {
position: absolute;
z-index: 10;
+ padding: 5px 0 5px;
}
}
diff --git a/src/components/Popover.tsx b/src/components/Popover.tsx
index ba424f3aed..630fee1c82 100644
--- a/src/components/Popover.tsx
+++ b/src/components/Popover.tsx
@@ -69,12 +69,27 @@ export const Popover = ({
if (fitInViewport && popoverRef.current) {
const element = popoverRef.current;
const { x, y, width, height } = element.getBoundingClientRect();
+ const { innerWidth: viewportWidth, innerHeight: viewportHeight } = window;
+
+ //Position correctly when clicked on rightmost part or the bottom part of viewport
if (x + width - offsetLeft > viewportWidth) {
- element.style.left = `${viewportWidth - width}px`;
+ element.style.left = `${viewportWidth - width - 10}px`;
}
if (y + height - offsetTop > viewportHeight) {
element.style.top = `${viewportHeight - height}px`;
}
+
+ //Resize to fit viewport on smaller screens
+ if (height >= viewportHeight) {
+ element.style.height = `${viewportHeight - 20}px`;
+ element.style.top = "10px";
+ element.style.overflowY = "scroll";
+ }
+ if (width >= viewportWidth) {
+ element.style.width = `${viewportWidth}px`;
+ element.style.left = "0px";
+ element.style.overflowX = "scroll";
+ }
}
}, [fitInViewport, viewportWidth, viewportHeight, offsetLeft, offsetTop]);