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