@@ -966,6 +966,34 @@ describe('CdkTree', () => {
966966 [ `topping_3 - cheese_3 + base_3` ] ,
967967 ) ;
968968 } ) ;
969+
970+ it ( 'should not collapse parent when child is toggled via keyboard' , ( ) => {
971+ component . toggleRecursively = false ;
972+ fixture . changeDetectorRef . markForCheck ( ) ;
973+ let data = dataSource . data ;
974+ const child = dataSource . addChild ( data [ 1 ] , false ) ;
975+ dataSource . addChild ( child , false ) ;
976+ fixture . detectChanges ( ) ;
977+
978+ // Expand parent
979+ ( getNodes ( treeElement ) [ 1 ] as HTMLElement ) . click ( ) ;
980+ fixture . detectChanges ( ) ;
981+
982+ expect ( component . tree . isExpanded ( data [ 1 ] ) ) . toBe ( true ) ;
983+
984+ // Focus child node (which is now at index 2)
985+ const childNode = getNodes ( treeElement ) [ 2 ] as HTMLElement ;
986+
987+ // Simulate Enter key on child node
988+ const event = createKeyboardEvent ( 'keydown' , undefined , 'Enter' ) ;
989+ childNode . dispatchEvent ( event ) ;
990+ fixture . detectChanges ( ) ;
991+
992+ // Verify parent is still expanded
993+ expect ( component . tree . isExpanded ( data [ 1 ] ) )
994+ . withContext ( 'Parent should remain expanded' )
995+ . toBe ( true ) ;
996+ } ) ;
969997 } ) ;
970998
971999 describe ( 'nested tree with array data source' , ( ) => {
0 commit comments