Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: auto adjust menu height & add scroll if necessary

thecodrr265c1e6454b9
diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index 082e69f21..241fdbd3f 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -1,5 +1,6 @@
import React, { useCallback, useEffect, useState } from "react";
import { Flex, Text } from "rebass";
+import { FlexScrollContainer } from "../scroll-container";
import MenuItem from "./menu-item";
function useMenuFocus(items, onAction) {
@@ -124,9 +125,6 @@ function MenuContainer({ title, children }) {
border: "1px solid var(--border)",
width: 220,
}}
- onKeyDown={(e) => {
- console.log("KEY!", e);
- }}
>
{title && (
<Text
@@ -140,7 +138,7 @@ function MenuContainer({ title, children }) {
{title}
</Text>
)}
- {children}
+ <FlexScrollContainer>{children}</FlexScrollContainer>
</Flex>
);
}
diff --git a/apps/web/src/hooks/use-menu.js b/apps/web/src/hooks/use-menu.js
index e6b6795e8..e9e15538b 100644
--- a/apps/web/src/hooks/use-menu.js
+++ b/apps/web/src/hooks/use-menu.js
@@ -86,6 +86,16 @@ export function getPosition(element, positionOptions) {
if (location === "below") position.top += height;
else if (location === "top") position.top -= height;
}
+
+ position.top = position.top < 0 ? 0 : position.top;
+ position.left = position.left < 0 ? 0 : position.left;
+
+ // Adjust menu height
+ if (elementHeight > windowHeight - position.top) {
+ element.style.maxHeight = `${windowHeight - 100}px`;
+ return getPosition(element, positionOptions);
+ }
+
return position;
}