diff --git a/app/components/ContextMenu/MenuItem.js b/app/components/ContextMenu/MenuItem.js
index 357c3e680..48a67bfe2 100644
--- a/app/components/ContextMenu/MenuItem.js
+++ b/app/components/ContextMenu/MenuItem.js
@@ -2,7 +2,7 @@
import { CheckmarkIcon } from "outline-icons";
import * as React from "react";
import { MenuItem as BaseMenuItem } from "reakit/Menu";
-import styled from "styled-components";
+import styled, { css } from "styled-components";
import breakpoint from "styled-components-breakpoint";
import MenuIconWrapper from "../MenuIconWrapper";
@@ -88,12 +88,12 @@ const Spacer = styled.svg`
flex-shrink: 0;
`;
-export const MenuAnchor = styled.a`
+export const MenuAnchorCSS = css`
display: flex;
margin: 0;
border: 0;
padding: 12px;
- padding-left: ${(props) => 12 + props.level * 10}px;
+ padding-left: ${(props) => 12 + (props.level || 0) * 10}px;
width: 100%;
min-height: 32px;
background: none;
@@ -138,5 +138,8 @@ export const MenuAnchor = styled.a`
font-size: 14px;
`};
`;
+export const MenuAnchor = styled.a`
+ ${MenuAnchorCSS}
+`;
export default MenuItem;
diff --git a/app/components/ContextMenu/index.js b/app/components/ContextMenu/index.js
index c215051d9..cb6cae861 100644
--- a/app/components/ContextMenu/index.js
+++ b/app/components/ContextMenu/index.js
@@ -4,9 +4,8 @@ import { Portal } from "react-portal";
import { Menu } from "reakit/Menu";
import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";
-import useMobile from "hooks/useMobile";
+import useMenuHeight from "hooks/useMenuHeight";
import usePrevious from "hooks/usePrevious";
-import useWindowSize from "hooks/useWindowSize";
import {
fadeIn,
fadeAndSlideUp,
@@ -35,9 +34,7 @@ export default function ContextMenu({
...rest
}: Props) {
const previousVisible = usePrevious(rest.visible);
- const [maxHeight, setMaxHeight] = React.useState(undefined);
- const isMobile = useMobile();
- const { height: windowHeight } = useWindowSize();
+ const maxHeight = useMenuHeight(rest.visible, rest.unstable_disclosureRef);
const backgroundRef = React.useRef();
React.useEffect(() => {
@@ -55,21 +52,6 @@ export default function ContextMenu({
// sets the menu height based on the available space between the disclosure/
// trigger and the bottom of the window
- React.useLayoutEffect(() => {
- const padding = 8;
-
- if (rest.visible && !isMobile) {
- setMaxHeight(
- rest.unstable_disclosureRef?.current
- ? windowHeight -
- rest.unstable_disclosureRef.current.getBoundingClientRect()
- .bottom -
- padding
- : undefined
- );
- }
- }, [rest.visible, rest.unstable_disclosureRef, windowHeight, isMobile]);
-
return (
<>