From b1330cb99a75022ccfd95f797f5dff0f5ca67353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 16 Aug 2024 12:12:00 +0200 Subject: [PATCH] Animate dropdown menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../dropdown-menu/dropdown-menu.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/dropdown-menu/dropdown-menu.tsx b/src/components/dropdown-menu/dropdown-menu.tsx index 3268cb106..50f5c1de8 100644 --- a/src/components/dropdown-menu/dropdown-menu.tsx +++ b/src/components/dropdown-menu/dropdown-menu.tsx @@ -50,6 +50,7 @@ const DropdownMenu = (props: IDropdownMenu) => { const history = useHistory(); const [isOpen, setIsOpen] = useState(false); + const [isDisplayed, setIsDisplayed] = useState(false); const arrowRef = useRef(null); @@ -254,12 +255,18 @@ const DropdownMenu = (props: IDropdownMenu) => { } }, [isOpen, refs.floating.current]); + useEffect(() => { + setTimeout(() => setIsDisplayed(isOpen), isOpen ? 0 : 150); + }, [isOpen]); + if (items.length === 0) { return null; } const autoFocus = !items.some((item) => item?.active); + console.log(placement); + return ( <> {children ? ( @@ -284,14 +291,23 @@ const DropdownMenu = (props: IDropdownMenu) => { /> )} - {isOpen ? ( + {isOpen || isDisplayed ? (