From 3264cc045b033274914f36661b39ead8d2ef80a2 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 22 Feb 2024 08:05:03 +0100 Subject: [PATCH] refactor(MenuProvider): code readability --- src/common/Menu/MenuProvider.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/Menu/MenuProvider.tsx b/src/common/Menu/MenuProvider.tsx index 8b71c25c6..bf6212f90 100644 --- a/src/common/Menu/MenuProvider.tsx +++ b/src/common/Menu/MenuProvider.tsx @@ -60,12 +60,13 @@ const MenuProvider = ({ children, className }: Props) => { const menu = container.current.getBoundingClientRect(); const parent = active.parent.getBoundingClientRect(); - const y = (parent.bottom + menu.height) > window.innerHeight ? 'top' : 'bottom'; - const x = (parent.right + menu.width) > window.innerWidth ? 'left' : 'right'; + const position = active.position; + const y = position ? position[0] : (parent.bottom + menu.height) > window.innerHeight ? 'top' : 'bottom'; + const x = position ? position[1] : (parent.right + menu.width) > window.innerWidth ? 'left' : 'right'; setStyle({ - top: (active.position?.[0] ?? y) === 'top' ? parent.top - menu.height : parent.bottom, - left: (active.position?.[1] ?? x) === 'left' ? parent.right - menu.width : parent.left, + top: y === 'top' ? parent.top - menu.height : parent.bottom, + left: x === 'left' ? parent.right - menu.width : parent.left, }); } }, [active]);