Skip to content

Commit

Permalink
fix(flat-pages): fix shortcuts style on big class room (#1911)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious authored May 5, 2023
1 parent bd2edc2 commit a892177
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/flat-pages/src/components/Shortcuts/Shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Shortcuts = observer<ShortcutsProps>(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<React.CSSProperties | undefined>(
() =>
rect && activeUser
Expand Down Expand Up @@ -155,3 +155,13 @@ export const Shortcuts = observer<ShortcutsProps>(function Shortcuts({ classroom
</div>
);
});

function hasAncestorWithClassName(el: HTMLElement | null, className: string): boolean {
if (!el) {
return false;
}
if (el.classList.contains(className)) {
return true;
}
return hasAncestorWithClassName(el.parentElement, className);
}

0 comments on commit a892177

Please sign in to comment.