MCPcopy Create free account
hub / github.com/angular/components / _monitorFocus

Method _monitorFocus

src/material/chips/chip.ts:425–444  ·  view source on GitHub ↗

Starts the focus monitoring process on the chip.

()

Source from the content-addressed store, hash-verified

423
424 /** Starts the focus monitoring process on the chip. */
425 private _monitorFocus() {
426 this._focusMonitor.monitor(this._elementRef, true).subscribe(origin => {
427 const hasFocus = origin !== null;
428
429 if (hasFocus !== this._hasFocusInternal) {
430 this._hasFocusInternal = hasFocus;
431
432 if (hasFocus) {
433 this._onFocus.next({chip: this});
434 } else {
435 // When animations are enabled, Angular may end up removing the chip from the DOM a little
436 // earlier than usual, causing it to be blurred and throwing off the logic in the chip list
437 // that moves focus to the next item. To work around the issue, we defer marking the chip
438 // as not focused until after the next render.
439 this._changeDetectorRef.markForCheck();
440 setTimeout(() => this._ngZone.run(() => this._onBlur.next({chip: this})));
441 }
442 }
443 });
444 }
445}

Callers 1

constructorMethod · 0.95

Calls 3

markForCheckMethod · 0.80
monitorMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected