Skip to content

Commit

Permalink
refactor(material/chips): Remove use of zone onStable for blur events
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Feb 28, 2024
1 parent 09111d0 commit 9bd076e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/material/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
booleanAttribute,
numberAttribute,
ANIMATION_MODULE_TYPE,
afterNextRender,
Injector,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Expand Down Expand Up @@ -239,6 +241,8 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
*/
_rippleLoader: MatRippleLoader = inject(MatRippleLoader);

private _injector = inject(Injector);

constructor(
public _changeDetectorRef: ChangeDetectorRef,
public _elementRef: ElementRef<HTMLElement>,
Expand Down Expand Up @@ -407,10 +411,10 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
// When animations are enabled, Angular may end up removing the chip from the DOM a little
// earlier than usual, causing it to be blurred and throwing off the logic in the chip list
// that moves focus not the next item. To work around the issue, we defer marking the chip
// as not focused until the next time the zone stabilizes.
this._ngZone.onStable
.pipe(take(1))
.subscribe(() => this._ngZone.run(() => this._onBlur.next({chip: this})));
// as not focused until after the next render.
afterNextRender(() => this._ngZone.run(() => this._onBlur.next({chip: this})), {
injector: this._injector,
});
}
}
});
Expand Down

0 comments on commit 9bd076e

Please sign in to comment.