Skip to content

Commit 9bd076e

Browse files
committed
refactor(material/chips): Remove use of zone onStable for blur events
1 parent 09111d0 commit 9bd076e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/material/chips/chip.ts

Lines changed: 8 additions & 4 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 {
@@ -239,6 +241,8 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
239241
*/
240242
_rippleLoader: MatRippleLoader = inject(MatRippleLoader);
241243

244+
private _injector = inject(Injector);
245+
242246
constructor(
243247
public _changeDetectorRef: ChangeDetectorRef,
244248
public _elementRef: ElementRef<HTMLElement>,
@@ -407,10 +411,10 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
407411
// When animations are enabled, Angular may end up removing the chip from the DOM a little
408412
// earlier than usual, causing it to be blurred and throwing off the logic in the chip list
409413
// 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})));
414+
// as not focused until after the next render.
415+
afterNextRender(() => this._ngZone.run(() => this._onBlur.next({chip: this})), {
416+
injector: this._injector,
417+
});
414418
}
415419
}
416420
});

0 commit comments

Comments
 (0)