Skip to content

Commit 20bf71c

Browse files
authored
refactor(material/chips): Remove use of zone onStable for blur events (#28659)
1 parent ce9a395 commit 20bf71c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/material/chips/chip.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
booleanAttribute,
3333
numberAttribute,
3434
ANIMATION_MODULE_TYPE,
35+
afterNextRender,
36+
Injector,
3537
} from '@angular/core';
3638
import {DOCUMENT} from '@angular/common';
3739
import {
@@ -42,7 +44,6 @@ import {
4244
} from '@angular/material/core';
4345
import {FocusMonitor} from '@angular/cdk/a11y';
4446
import {merge, Subject, Subscription} from 'rxjs';
45-
import {take} from 'rxjs/operators';
4647
import {MatChipAvatar, MatChipTrailingIcon, MatChipRemove} from './chip-icons';
4748
import {MatChipAction} from './chip-action';
4849
import {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

Comments
 (0)