mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-11-09 15:24:25 +01:00
fix: close floating sidebar on main menu open (#10295)
This commit is contained in:
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -24,7 +24,6 @@ const MenuTrigger = ({
|
||||
).trim();
|
||||
return (
|
||||
<button
|
||||
data-prevent-outside-click
|
||||
className={classNames}
|
||||
onClick={onToggle}
|
||||
type="button"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user