Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions apps/web/core/components/sidebar/sidebar-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { useEffect, useRef, useState } from "react";
import { observer } from "mobx-react";
// plane helpers
import { useOutsideClickDetector } from "@plane/hooks";
import { PreferencesIcon } from "@plane/propel/icons";
import { ScrollArea } from "@plane/propel/scrollarea";
// components
Expand Down Expand Up @@ -36,12 +35,6 @@ export const SidebarWrapper = observer(function SidebarWrapper(props: TSidebarWr
// refs
const ref = useRef<HTMLDivElement>(null);

useOutsideClickDetector(ref, () => {
if (sidebarCollapsed === false && window.innerWidth < 768) {
toggleSidebar();
}
});

useEffect(() => {
if (windowSize[0] < 768 && !sidebarCollapsed) toggleSidebar();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
31 changes: 0 additions & 31 deletions packages/hooks/src/use-outside-click-detector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,3 @@
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/

import type React from "react";
import { useEffect } from "react";

export const useOutsideClickDetector = (
ref: React.RefObject<HTMLElement> | any,
callback: () => void,
useCapture = false
) => {
const handleClick = (event: MouseEvent) => {
if (ref.current && !ref.current.contains(event.target as any)) {
// check for the closest element with attribute name data-prevent-outside-click
const preventOutsideClickElement = (event.target as unknown as HTMLElement | undefined)?.closest(
"[data-prevent-outside-click]"
);
// if the closest element with attribute name data-prevent-outside-click is found, return
if (preventOutsideClickElement) {
return;
}
// else call the callback
callback();
}
};

useEffect(() => {
document.addEventListener("mousedown", handleClick, useCapture);
return () => {
document.removeEventListener("mousedown", handleClick, useCapture);
};
});
};