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

Method _monitorFocus

src/material/chips/chip.ts:404–423  ·  view source on GitHub ↗

Starts the focus monitoring process on the chip.

()

Source from the content-addressed store, hash-verified

402
403 /** Starts the focus monitoring process on the chip. */
404 private _monitorFocus() {
405 this._focusMonitor.monitor(this._elementRef, true).subscribe(origin => {
406 const hasFocus = origin !== null;
407
408 if (hasFocus !== this._hasFocusInternal) {
409 this._hasFocusInternal = hasFocus;
410
411 if (hasFocus) {
412 this._onFocus.next({chip: this});
413 } else {
414 // When animations are enabled, Angular may end up removing the chip from the DOM a little
415 // earlier than usual, causing it to be blurred and throwing off the logic in the chip list
416 // that moves focus to the next item. To work around the issue, we defer marking the chip
417 // as not focused until after the next render.
418 this._changeDetectorRef.markForCheck();
419 setTimeout(() => this._ngZone.run(() => this._onBlur.next({chip: this})));
420 }
421 }
422 });
423 }
424}

Callers 1

constructorMethod · 0.95

Calls 3

markForCheckMethod · 0.80
monitorMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected