From 8eb0d9b273a6b81f06f8572c88aee36b66bc2d19 Mon Sep 17 00:00:00 2001 From: hyrious Date: Fri, 5 May 2023 11:17:03 +0800 Subject: [PATCH] fix(flat-pages): fix shortcuts style on big class room --- .../src/components/Shortcuts/Shortcuts.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/flat-pages/src/components/Shortcuts/Shortcuts.tsx b/packages/flat-pages/src/components/Shortcuts/Shortcuts.tsx index f3a93344d2d..0729482a66d 100644 --- a/packages/flat-pages/src/components/Shortcuts/Shortcuts.tsx +++ b/packages/flat-pages/src/components/Shortcuts/Shortcuts.tsx @@ -26,7 +26,7 @@ export const Shortcuts = observer(function Shortcuts({ classroom ); const { height: windowHeight } = useWindowSize(); const rect = useBoundingRect(target); - const isAvatarWindow = useMemo(() => target?.classList.contains("window-main"), [target]); + const isAvatarWindow = useMemo(() => hasAncestorWithClassName(target, "window-main"), [target]); const style = useMemo( () => rect && activeUser @@ -155,3 +155,13 @@ export const Shortcuts = observer(function Shortcuts({ classroom ); }); + +function hasAncestorWithClassName(el: HTMLElement | null, className: string): boolean { + if (!el) { + return false; + } + if (el.classList.contains(className)) { + return true; + } + return hasAncestorWithClassName(el.parentElement, className); +}