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;
return (
<>
<div
className="dropdown-menu-container"
style={{
// remove this div from box layout
display: "contents",
}}
>
{MenuTriggerComp}
{open && MenuContentCompWithPlacement}
</>
</div>
);
};

View File

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

View File

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

View File

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

View File

@@ -5,7 +5,7 @@ import { EVENT } from "@excalidraw/common";
export function useOutsideClick<T extends HTMLElement>(
ref: React.RefObject<T | null>,
/** 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.
*