@@ -14,6 +14,7 @@ import {DOMAttributes, FocusableElement, FocusStrategy, KeyboardDelegate} from '
1414import { FocusEvent , Key , KeyboardEvent , RefObject , useEffect , useRef } from 'react' ;
1515import { focusSafely , getFocusableTreeWalker } from '@react-aria/focus' ;
1616import { focusWithoutScrolling , mergeProps , scrollIntoView , scrollIntoViewport , useEvent } from '@react-aria/utils' ;
17+ import { getInteractionModality } from '@react-aria/interactions' ;
1718import { isCtrlKeyPressed , isNonContiguousSelectionModifier } from './utils' ;
1819import { MultipleSelectionManager } from '@react-stately/selection' ;
1920import { useLocale } from '@react-aria/i18n' ;
@@ -356,14 +357,17 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
356357 // If not virtualized, scroll the focused element into view when the focusedKey changes.
357358 // When virtualized, Virtualizer handles this internally.
358359 useEffect ( ( ) => {
359- if ( ! isVirtualized && manager . focusedKey && scrollRef ?. current ) {
360+ let modality = getInteractionModality ( ) ;
361+ if ( ! isVirtualized && manager . isFocused && manager . focusedKey != null && scrollRef ?. current ) {
360362 let element = scrollRef . current . querySelector ( `[data-key="${ manager . focusedKey } "]` ) as HTMLElement ;
361363 if ( element ) {
362364 scrollIntoView ( scrollRef . current , element ) ;
363- scrollIntoViewport ( element , { containingElement : ref . current } ) ;
365+ if ( modality === 'keyboard' ) {
366+ scrollIntoViewport ( element , { containingElement : ref . current } ) ;
367+ }
364368 }
365369 }
366- } , [ isVirtualized , scrollRef , manager . focusedKey , ref ] ) ;
370+ } , [ isVirtualized , scrollRef , manager . focusedKey , manager . isFocused , ref ] ) ;
367371
368372 let handlers = {
369373 onKeyDown,
0 commit comments