UI - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: portal popup рабочей области и sidebar-search

This commit is contained in:
DCCONSTRUCTIONS
2026-04-19 18:32:36 +03:00
parent b46390ccdd
commit 01eb3d4c8a
4 changed files with 232 additions and 111 deletions
@@ -4,11 +4,12 @@
* See the LICENSE file for details.
*/
import { useCallback, useEffect, useRef, useState } from "react";
import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
import { useOutsideClickDetector } from "@plane/hooks";
type UseExpandableSearchOptions = {
onClose?: () => void;
additionalRefs?: Array<RefObject<HTMLElement | null>>;
};
/**
@@ -17,7 +18,7 @@ type UseExpandableSearchOptions = {
* Opens on click, typing, or keyboard shortcut (via PowerK Cmd+F)
*/
export const useExpandableSearch = (options?: UseExpandableSearchOptions) => {
const { onClose } = options || {};
const { onClose, additionalRefs = [] } = options || {};
// states
const [isOpen, setIsOpen] = useState(false);
@@ -28,6 +29,15 @@ export const useExpandableSearch = (options?: UseExpandableSearchOptions) => {
const wasClickedRef = useRef<boolean>(false);
const wasKeyboardTriggeredRef = useRef<boolean>(false);
const isWithinTrackedElements = useCallback(
(target: Node | null) => {
if (!target) return false;
if (containerRef.current?.contains(target)) return true;
return additionalRefs.some((ref) => ref.current?.contains(target));
},
[additionalRefs]
);
// Handle close
const handleClose = useCallback(() => {
setIsOpen(false);
@@ -51,7 +61,7 @@ export const useExpandableSearch = (options?: UseExpandableSearchOptions) => {
const handlePointerDown = (event: PointerEvent) => {
const target = event.target as Node | null;
if (!target) return;
if (containerRef.current?.contains(target)) return;
if (isWithinTrackedElements(target)) return;
handleClose();
};
@@ -59,7 +69,7 @@ export const useExpandableSearch = (options?: UseExpandableSearchOptions) => {
return () => {
document.removeEventListener("pointerdown", handlePointerDown, true);
};
}, [isOpen, handleClose]);
}, [handleClose, isOpen, isWithinTrackedElements]);
// Track keyboard shortcuts that trigger focus (Cmd+F / Ctrl+F)
useEffect(() => {