@@ -32,6 +32,8 @@ import {
3232 booleanAttribute ,
3333 numberAttribute ,
3434 ANIMATION_MODULE_TYPE ,
35+ afterNextRender ,
36+ Injector ,
3537} from '@angular/core' ;
3638import { DOCUMENT } from '@angular/common' ;
3739import {
@@ -42,7 +44,6 @@ import {
4244} from '@angular/material/core' ;
4345import { FocusMonitor } from '@angular/cdk/a11y' ;
4446import { merge , Subject , Subscription } from 'rxjs' ;
45- import { take } from 'rxjs/operators' ;
4647import { MatChipAvatar , MatChipTrailingIcon , MatChipRemove } from './chip-icons' ;
4748import { MatChipAction } from './chip-action' ;
4849import { BACKSPACE , DELETE } from '@angular/cdk/keycodes' ;
@@ -239,6 +240,8 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
239240 */
240241 _rippleLoader : MatRippleLoader = inject ( MatRippleLoader ) ;
241242
243+ private _injector = inject ( Injector ) ;
244+
242245 constructor (
243246 public _changeDetectorRef : ChangeDetectorRef ,
244247 public _elementRef : ElementRef < HTMLElement > ,
@@ -407,10 +410,10 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
407410 // When animations are enabled, Angular may end up removing the chip from the DOM a little
408411 // earlier than usual, causing it to be blurred and throwing off the logic in the chip list
409412 // that moves focus not the next item. To work around the issue, we defer marking the chip
410- // as not focused until the next time the zone stabilizes .
411- this . _ngZone . onStable
412- . pipe ( take ( 1 ) )
413- . subscribe ( ( ) => this . _ngZone . run ( ( ) => this . _onBlur . next ( { chip : this } ) ) ) ;
413+ // as not focused until after the next render .
414+ afterNextRender ( ( ) => this . _ngZone . run ( ( ) => this . _onBlur . next ( { chip : this } ) ) , {
415+ injector : this . _injector ,
416+ } ) ;
414417 }
415418 }
416419 } ) ;
0 commit comments