From fe3ff1215eca5bb40de1dfa1f55a393726f6dd73 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 12 Sep 2022 10:12:42 +0100 Subject: [PATCH] Make submenus dismissable on mobile, alternative solution closes #3948 --- app/components/ContextMenu/index.tsx | 61 +++++++++++++++------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/app/components/ContextMenu/index.tsx b/app/components/ContextMenu/index.tsx index a5ab81df8..787601306 100644 --- a/app/components/ContextMenu/index.tsx +++ b/app/components/ContextMenu/index.tsx @@ -1,7 +1,6 @@ import { disableBodyScroll, enableBodyScroll } from "body-scroll-lock"; import * as React from "react"; import { useTranslation } from "react-i18next"; -import { Portal } from "react-portal"; import { Menu } from "reakit/Menu"; import styled, { DefaultTheme } from "styled-components"; import breakpoint from "styled-components-breakpoint"; @@ -9,6 +8,7 @@ import { depths } from "@shared/styles"; import Scrollable from "~/components/Scrollable"; import useMenuContext from "~/hooks/useMenuContext"; import useMenuHeight from "~/hooks/useMenuHeight"; +import useMobile from "~/hooks/useMobile"; import usePrevious from "~/hooks/usePrevious"; import useStores from "~/hooks/useStores"; import useUnmount from "~/hooks/useUnmount"; @@ -59,6 +59,7 @@ const ContextMenu: React.FC = ({ const { ui } = useStores(); const { t } = useTranslation(); const { setIsMenuOpen } = useMenuContext(); + const isMobile = useMobile(); useUnmount(() => { setIsMenuOpen(false); @@ -115,7 +116,7 @@ const ContextMenu: React.FC = ({ // trigger and the bottom of the window return ( <> - + {(props) => { // kind of hacky, but this is an effective way of telling which way // the menu will _actually_ be placed when taking into account screen @@ -125,32 +126,38 @@ const ContextMenu: React.FC = ({ const rightAnchor = props.placement === "bottom-end"; return ( - - - {rest.visible || rest.animating ? children : null} - - + <> + {isMobile && ( + { + ev.preventDefault(); + ev.stopPropagation(); + rest.hide?.(); + }} + /> + )} + + + {rest.visible || rest.animating ? children : null} + + + ); }} - {(rest.visible || rest.animating) && ( - - - - )} ); }; @@ -166,10 +173,6 @@ export const Backdrop = styled.div` bottom: 0; background: ${(props) => props.theme.backdrop}; z-index: ${depths.menu - 1}; - - ${breakpoint("tablet")` - display: none; - `}; `; export const Position = styled.div`