44 PropsWithChildren ,
55 ReactNode ,
66 RefObject ,
7- useEffect ,
87 useMemo ,
98 useRef ,
109 useState ,
@@ -14,43 +13,13 @@ import { Slot } from "@radix-ui/react-slot"
1413
1514import { Button } from "components/ui/button"
1615import { Portal } from "components/utility/portal"
16+ import { useFocus } from "hooks/use-focus"
1717import { ClassNameProp } from "types/base-props"
1818import { cn } from "utils/cn"
1919import { fuzzyFilter } from "utils/fuzzy-filter"
2020import { surface } from "utils/styles"
2121import { zIndex } from "utils/z-index"
2222
23- const useFocus = ( refs : RefObject < Element | null > [ ] ) => {
24- const [ focus , setFocus ] = useState ( false )
25-
26- useEffect ( ( ) => {
27- const handler = ( ) => {
28- const elements = refs
29- . map ( ( { current } ) => current )
30- . filter ( Boolean ) as Element [ ]
31-
32- const target = document . activeElement
33- const focus = elements . some (
34- element => element === target || element . contains ( target )
35- )
36-
37- setFocus ( ! ! focus )
38- }
39-
40- window . addEventListener ( "focusin" , handler )
41- window . addEventListener ( "click" , handler )
42-
43- return ( ) => {
44- window . removeEventListener ( "focusin" , handler )
45- window . removeEventListener ( "click" , handler )
46- }
47- // eslint-disable-next-line react-compiler/react-compiler
48- // eslint-disable-next-line react-hooks/exhaustive-deps
49- } , refs )
50-
51- return focus
52- }
53-
5423const useBoundingRect = ( ) => {
5524 const [ boundingRect , setBoundingRect ] =
5625 useState < ReturnType < Element [ "getBoundingClientRect" ] > > ( )
0 commit comments