@@ -187,6 +187,7 @@ const LookupSelectedState: FC<LookupSelectedStateProps> = ({
187187 */
188188type LookupScopeSelectorContainerProps = {
189189 scopeListboxId : string ;
190+ dropdownRef : React . MutableRefObject < HTMLDivElement | null > ;
190191 children : React . ReactNode ;
191192} & AutoAlignInjectedProps ;
192193
@@ -195,6 +196,7 @@ type LookupScopeSelectorContainerProps = {
195196 */
196197const LookupScopeSelectorContainer : FC < LookupScopeSelectorContainerProps > = ( {
197198 scopeListboxId,
199+ dropdownRef,
198200 children,
199201 alignment,
200202 autoAlignContentRef,
@@ -214,7 +216,7 @@ const LookupScopeSelectorContainer: FC<LookupScopeSelectorContainerProps> = ({
214216 className = { dropdownClassNames }
215217 role = 'listbox'
216218 aria-label = 'Scope Options'
217- ref = { useMergeRefs ( [ autoAlignContentRef ] ) }
219+ ref = { useMergeRefs ( [ dropdownRef , autoAlignContentRef ] ) }
218220 >
219221 { children }
220222 </ div >
@@ -248,6 +250,8 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
248250 onScopeMenuClick : onScopeMenuClick_ ,
249251 onScopeSelect : onScopeSelect_ ,
250252} ) => {
253+ const dropdownRef = useRef < HTMLDivElement | null > ( null ) ;
254+
251255 const [ scopeOpened , setScopeOpened ] = useState ( false ) ;
252256 const [ scopeFocusedIndex , setScopeFocusedIndex ] = useState < number > ( - 1 ) ;
253257
@@ -379,10 +383,18 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
379383 }
380384
381385 setTimeout ( ( ) => {
382- setScopeOpened ( false ) ;
386+ if ( ! isFocusedInComponent ( ) ) {
387+ setScopeOpened ( false ) ;
388+ }
383389 } , 10 ) ;
384390 } ) ;
385391
392+ const { getActiveElement } = useContext ( ComponentSettingsContext ) ;
393+ const isFocusedInComponent = useEventCallback ( ( ) => {
394+ const targetEl = getActiveElement ( ) ;
395+ return isElInChildren ( dropdownRef . current , targetEl ) ;
396+ } ) ;
397+
386398 return (
387399 < div className = 'react-slds-lookup-scope-selector slds-combobox_object-switcher slds-combobox-addon_start' >
388400 < div className = 'slds-form-element' >
@@ -442,6 +454,7 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
442454 { ( injectedProps ) => (
443455 < LookupScopeSelectorContainer
444456 scopeListboxId = { scopeListboxId }
457+ dropdownRef = { dropdownRef }
445458 { ...injectedProps }
446459 >
447460 < ul
0 commit comments