@@ -1485,4 +1485,50 @@ describe('Tree Basic', () => {
14851485 expect ( scrollToSpy ) . not . toHaveBeenCalled ( ) ;
14861486 scrollToSpy . mockRestore ( ) ;
14871487 } ) ;
1488+
1489+ it . each ( [
1490+ { description : 'a selected node' , treeProps : { selectedKeys : [ '1' ] } } ,
1491+ { description : 'selection disabled' , treeProps : { selectable : false } } ,
1492+ ] ) (
1493+ 'should not scroll when an interactive title descendant receives focus with $description' ,
1494+ ( { treeProps } ) => {
1495+ const data = Array . from ( { length : 20 } , ( _ , index ) => ( {
1496+ key : String ( index ) ,
1497+ title : `Node ${ index } ` ,
1498+ } ) ) ;
1499+ const treeRef = React . createRef < any > ( ) ;
1500+ const onFocus = jest . fn ( ) ;
1501+ const { getByRole } = render (
1502+ < Tree
1503+ ref = { treeRef }
1504+ treeData = { data }
1505+ height = { 100 }
1506+ itemHeight = { 20 }
1507+ titleRender = { node =>
1508+ node . key === '0' ? (
1509+ < select aria-label = "Node action" >
1510+ < option > Action</ option >
1511+ </ select >
1512+ ) : (
1513+ node . title
1514+ )
1515+ }
1516+ onFocus = { onFocus }
1517+ { ...treeProps }
1518+ /> ,
1519+ ) ;
1520+ const select = getByRole ( 'combobox' ) ;
1521+ const scrollToSpy = jest . spyOn ( treeRef . current , 'scrollTo' ) ;
1522+
1523+ fireEvent . mouseDown ( select ) ;
1524+ fireEvent . mouseUp ( select ) ;
1525+ expect ( treeRef . current . focusedByMouse ) . toBe ( false ) ;
1526+
1527+ fireEvent . focus ( select ) ;
1528+
1529+ expect ( onFocus ) . toHaveBeenCalledTimes ( 1 ) ;
1530+ expect ( scrollToSpy ) . not . toHaveBeenCalled ( ) ;
1531+ scrollToSpy . mockRestore ( ) ;
1532+ } ,
1533+ ) ;
14881534} ) ;
0 commit comments