@@ -3709,21 +3709,25 @@ export abstract class IgxGridBaseDirective implements GridType,
37093709 */
37103710 public _setupListeners ( ) {
37113711 const destructor = takeUntil < any > ( this . destroy$ ) ;
3712- fromEvent ( this . document , 'focusin' )
3713- . pipe ( filter ( ( ) => ! ! this . navigation . activeNode ) , destructor )
3714- . subscribe ( ( event : FocusEvent ) => {
3715- if ( this . crudService . cell || ! this . navigation . activeNode ) {
3716- return ;
3717- }
3718- if ( this . rowEditable && this . crudService . rowEditingBlocked && this . crudService . rowInEditMode ) {
3719- return ;
3720- }
3721- const target = event . target as Node ;
3722- if ( target && this . nativeElement . contains ( target ) ) {
3723- return ;
3724- }
3725- Promise . resolve ( ) . then ( ( ) => this . clearActiveNode ( ) ) ;
3726- } ) ;
3712+ fromEvent ( this . nativeElement , 'focusout' ) . pipe ( filter ( ( ) => ! ! this . navigation . activeNode ) , destructor ) . subscribe ( ( event ) => {
3713+ const activeNode = this . navigation . activeNode ;
3714+
3715+ // In hierarchical grids, activation can be cleared by child highlight logic, leaving an empty object.
3716+ // If merging is enabled, clear cached active indexes to allow merge state to restore.
3717+ if ( ! Object . keys ( activeNode ) . length && this . hasCellsToMerge ) {
3718+ this . _activeRowIndexes = null ;
3719+ this . notifyChanges ( ) ;
3720+ }
3721+
3722+ if ( ! this . crudService . cell && ! ! activeNode &&
3723+ ( ( event . target === this . tbody . nativeElement && activeNode . row >= 0 &&
3724+ activeNode . row < this . dataView . length )
3725+ || ( event . target === this . theadRow . nativeElement && activeNode . row === - 1 )
3726+ || ( event . target === this . tfoot . nativeElement && activeNode . row === this . dataView . length ) ) &&
3727+ ! ( this . rowEditable && this . crudService . rowEditingBlocked && this . crudService . rowInEditMode ) ) {
3728+ this . clearActiveNode ( ) ;
3729+ }
3730+ } ) ;
37273731 this . rowAddedNotifier . pipe ( destructor ) . subscribe ( args => this . refreshGridState ( args ) ) ;
37283732 this . rowDeletedNotifier . pipe ( destructor ) . subscribe ( args => {
37293733 this . summaryService . deleteOperation = true ;
0 commit comments