@@ -61,6 +61,40 @@ describe('<Tree />', () => {
6161 expect ( info . node . key ) . toBe ( 'fruits' ) ;
6262 } ) ;
6363
64+ it ( 'reports the correct toggled node across multiple uncontrolled toggles' , async ( ) => {
65+ const onExpand = vi . fn ( ) ;
66+ const { getAllByRole } = renderWithRoot (
67+ < Tree
68+ treeData = { SAMPLE }
69+ defaultExpandedKeys = { [ 'fruits' ] }
70+ onExpand = { onExpand }
71+ /> ,
72+ ) ;
73+
74+ const rows = getAllByRole ( 'row' ) ;
75+ const fruitsToggle = rows [ 0 ] . querySelector (
76+ 'button[data-element="Toggle"]' ,
77+ ) as HTMLButtonElement ;
78+ const vegetablesToggle = rows [ 3 ] . querySelector (
79+ 'button[data-element="Toggle"]' ,
80+ ) as HTMLButtonElement ;
81+
82+ await act ( async ( ) => await userEvent . click ( vegetablesToggle ) ) ;
83+ let [ , info ] = onExpand . mock . calls [ onExpand . mock . calls . length - 1 ] ;
84+ expect ( info . expanded ) . toBe ( true ) ;
85+ expect ( info . node . key ) . toBe ( 'vegetables' ) ;
86+
87+ await act ( async ( ) => await userEvent . click ( fruitsToggle ) ) ;
88+ [ , info ] = onExpand . mock . calls [ onExpand . mock . calls . length - 1 ] ;
89+ expect ( info . expanded ) . toBe ( false ) ;
90+ expect ( info . node . key ) . toBe ( 'fruits' ) ;
91+
92+ await act ( async ( ) => await userEvent . click ( vegetablesToggle ) ) ;
93+ [ , info ] = onExpand . mock . calls [ onExpand . mock . calls . length - 1 ] ;
94+ expect ( info . expanded ) . toBe ( false ) ;
95+ expect ( info . node . key ) . toBe ( 'vegetables' ) ;
96+ } ) ;
97+
6498 describe ( 'checkable mode' , ( ) => {
6599 it ( 'renders checkboxes when isCheckable is true' , ( ) => {
66100 const { getAllByRole } = renderWithRoot (
0 commit comments