mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-11-14 17:54:47 +01:00
fix: close floating sidebar on main menu open (#10295)
This commit is contained in:
@@ -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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,15 @@ const MenuContent = ({
|
|||||||
|
|
||||||
const callbacksRef = useStable({ onClickOutside });
|
const callbacksRef = useStable({ onClickOutside });
|
||||||
|
|
||||||
useOutsideClick(menuRef, () => {
|
useOutsideClick(menuRef, (event) => {
|
||||||
|
// prevents closing if clicking on the trigger button
|
||||||
|
if (
|
||||||
|
!menuRef.current
|
||||||
|
?.closest(".dropdown-menu-container")
|
||||||
|
?.contains(event.target)
|
||||||
|
) {
|
||||||
callbacksRef.onClickOutside?.();
|
callbacksRef.onClickOutside?.();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user