fix: close floating sidebar on main menu open (#10295)

This commit is contained in:
David Luzar
2025-11-06 22:39:39 +01:00
committed by GitHub
parent 95ddc66339
commit f2600fe3e8
5 changed files with 19 additions and 7 deletions

View File

@@ -35,10 +35,16 @@ const DropdownMenu = ({
: MenuContentComp; : MenuContentComp;
return ( return (
<> <div
className="dropdown-menu-container"
style={{
// remove this div from box layout
display: "contents",
}}
>
{MenuTriggerComp} {MenuTriggerComp}
{open && MenuContentCompWithPlacement} {open && MenuContentCompWithPlacement}
</> </div>
); );
}; };

View File

@@ -34,8 +34,15 @@ const MenuContent = ({
const callbacksRef = useStable({ onClickOutside }); const callbacksRef = useStable({ onClickOutside });
useOutsideClick(menuRef, () => { useOutsideClick(menuRef, (event) => {
callbacksRef.onClickOutside?.(); // prevents closing if clicking on the trigger button
if (
!menuRef.current
?.closest(".dropdown-menu-container")
?.contains(event.target)
) {
callbacksRef.onClickOutside?.();
}
}); });
useEffect(() => { useEffect(() => {

View File

@@ -24,7 +24,6 @@ const MenuTrigger = ({
).trim(); ).trim();
return ( return (
<button <button
data-prevent-outside-click
className={classNames} className={classNames}
onClick={onToggle} onClick={onToggle}
type="button" type="button"

View File

@@ -13,10 +13,10 @@
--zIndex-hyperlinkContainer: 7; --zIndex-hyperlinkContainer: 7;
--zIndex-ui-bottom: 60; --zIndex-ui-bottom: 60;
--zIndex-ui-library: 80;
--zIndex-ui-context-menu: 90; --zIndex-ui-context-menu: 90;
--zIndex-ui-styles-popup: 100; --zIndex-ui-styles-popup: 100;
--zIndex-ui-top: 100; --zIndex-ui-top: 100;
--zIndex-ui-library: 120;
--zIndex-modal: 1000; --zIndex-modal: 1000;
--zIndex-popup: 1001; --zIndex-popup: 1001;

View File

@@ -5,7 +5,7 @@ import { EVENT } from "@excalidraw/common";
export function useOutsideClick<T extends HTMLElement>( export function useOutsideClick<T extends HTMLElement>(
ref: React.RefObject<T | null>, ref: React.RefObject<T | null>,
/** if performance is of concern, memoize the callback */ /** if performance is of concern, memoize the callback */
callback: (event: Event) => void, callback: (event: Event & { target: T }) => void,
/** /**
* Optional callback which is called on every click. * Optional callback which is called on every click.
* *