@@ -5,6 +5,7 @@ import React, {
55 KeyboardEvent ,
66 Ref ,
77 useRef ,
8+ useContext ,
89 useState ,
910 useEffect ,
1011 ReactNode ,
@@ -19,10 +20,11 @@ import { Button } from './Button';
1920import { FormElement , FormElementProps } from './FormElement' ;
2021import { Icon , IconCategory } from './Icon' ;
2122import { Spinner } from './Spinner' ;
23+ import { isElInChildren , registerStyle } from './util' ;
24+ import { ComponentSettingsContext } from './ComponentSettings' ;
2225import { useControlledValue , useEventCallback , useMergeRefs } from './hooks' ;
2326import { createFC } from './common' ;
2427import { Bivariant } from './typeUtils' ;
25- import { registerStyle } from './util' ;
2628
2729/**
2830 *
@@ -1175,18 +1177,24 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
11751177 }
11761178 }
11771179
1178- const isComplete = ! containerRef . current ?. contains ( e . relatedTarget ) ;
1179-
11801180 setTimeout ( ( ) => {
1181- setOpened ( false ) ;
1182- onBlur_ ?.( ) ;
1183-
1184- if ( isComplete ) {
1181+ if ( ! isFocusedInComponent ( ) ) {
1182+ setOpened ( false ) ;
1183+ onBlur_ ?.( ) ;
11851184 onComplete ?.( true ) ;
11861185 }
11871186 } , 10 ) ;
11881187 } ) ;
11891188
1189+ const { getActiveElement } = useContext ( ComponentSettingsContext ) ;
1190+ const isFocusedInComponent = useEventCallback ( ( ) => {
1191+ const targetEl = getActiveElement ( ) ;
1192+ return (
1193+ isElInChildren ( containerRef . current , targetEl ) ||
1194+ isElInChildren ( dropdownElRef . current , targetEl )
1195+ ) ;
1196+ } ) ;
1197+
11901198 const onInputKeyDown = useKeyHandler ( {
11911199 type : 'search' ,
11921200 opened,
0 commit comments