From 7d791b86f84b056feb382d315667aa1f08a150cf Mon Sep 17 00:00:00 2001 From: barnabasmolnar Date: Tue, 18 Apr 2023 14:57:25 +0200 Subject: [PATCH] Attempt to fix submenu not disappearing properly. --- src/components/dropdownMenu/DropdownMenu.scss | 6 ++ .../dropdownMenu/DropdownMenuItem.tsx | 27 +++++---- .../dropdownMenu/DropdownMenuSubItem.tsx | 26 ++++---- .../dropdownMenu/DropdownMenuSubTrigger.tsx | 19 +++--- src/packages/excalidraw/example/App.tsx | 60 ++++++++++++++++++- 5 files changed, 106 insertions(+), 32 deletions(-) diff --git a/src/components/dropdownMenu/DropdownMenu.scss b/src/components/dropdownMenu/DropdownMenu.scss index 1b5fd1f39..e1da2aec1 100644 --- a/src/components/dropdownMenu/DropdownMenu.scss +++ b/src/components/dropdownMenu/DropdownMenu.scss @@ -8,6 +8,12 @@ .dropdown-menu { position: absolute; + .radix-menuitem { + &:focus-visible { + outline: none; + } + } + &--mobile { bottom: 55px; top: auto; diff --git a/src/components/dropdownMenu/DropdownMenuItem.tsx b/src/components/dropdownMenu/DropdownMenuItem.tsx index 5532dbaae..f9759cc3d 100644 --- a/src/components/dropdownMenu/DropdownMenuItem.tsx +++ b/src/components/dropdownMenu/DropdownMenuItem.tsx @@ -1,10 +1,11 @@ -import React from "react"; import { getDropdownMenuItemClassName, useHandleDropdownMenuItemClick, } from "./common"; import MenuItemContent from "./DropdownMenuItemContent"; +import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; + const DropdownMenuItem = ({ icon, onSelect, @@ -22,17 +23,19 @@ const DropdownMenuItem = ({ const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect); return ( - + + + ); }; diff --git a/src/components/dropdownMenu/DropdownMenuSubItem.tsx b/src/components/dropdownMenu/DropdownMenuSubItem.tsx index ade5139bc..f27033a43 100644 --- a/src/components/dropdownMenu/DropdownMenuSubItem.tsx +++ b/src/components/dropdownMenu/DropdownMenuSubItem.tsx @@ -4,6 +4,8 @@ import { useHandleDropdownMenuItemClick, } from "./common"; +import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; + const DropdownMenuSubItem = ({ icon, onSelect, @@ -21,17 +23,19 @@ const DropdownMenuSubItem = ({ const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect); return ( - + + + ); }; diff --git a/src/components/dropdownMenu/DropdownMenuSubTrigger.tsx b/src/components/dropdownMenu/DropdownMenuSubTrigger.tsx index ab6ef353a..5d3087566 100644 --- a/src/components/dropdownMenu/DropdownMenuSubTrigger.tsx +++ b/src/components/dropdownMenu/DropdownMenuSubTrigger.tsx @@ -8,19 +8,24 @@ const DropdownMenuSubTrigger = ({ icon, shortcut, className, + ...rest }: { children: React.ReactNode; icon?: JSX.Element; shortcut?: string; className?: string; -}) => { +} & React.HTMLAttributes) => { return ( - - - {children} - + +
+ + {children} + +
); }; diff --git a/src/packages/excalidraw/example/App.tsx b/src/packages/excalidraw/example/App.tsx index 4707a63da..d944fd68e 100644 --- a/src/packages/excalidraw/example/App.tsx +++ b/src/packages/excalidraw/example/App.tsx @@ -507,9 +507,45 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) { return ( - Trigger + + + + } + > + Trigger + + + + } onSelect={() => window.alert("You clicked on sub item")} > Sub item @@ -523,10 +559,30 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) { isCollaborating={isCollaborating} onSelect={() => window.alert("You clicked on collab button")} /> + + Trigger + + window.alert("You clicked on sub item")} + > + Sub item + + + - + {/* */} + + Trigger + + window.alert("You clicked on sub item")} + > + Sub item + + +