MCPcopy
hub / github.com/angular/components / focus

Method focus

src/material/chips/chip-grid.ts:323–347  ·  view source on GitHub ↗

* Focuses the first chip in this chip grid, or the associated input when there * are no eligible chips.

()

Source from the content-addressed store, hash-verified

321 * are no eligible chips.
322 */
323 override focus(): void {
324 if (this.disabled || this._chipInput?.focused) {
325 return;
326 }
327
328 if (!this._chips.length || this._chips.first.disabled) {
329 if (!this._chipInput) {
330 return;
331 }
332
333 // Delay until the next tick, because this can cause a "changed after checked"
334 // error if the input does something on focus (e.g. opens an autocomplete).
335 Promise.resolve().then(() => this._chipInput!.focus());
336 } else {
337 const activeItem = this._keyManager.activeItem;
338
339 if (activeItem) {
340 activeItem.focus();
341 } else {
342 this._keyManager.setFirstItemActive();
343 }
344 }
345
346 this.stateChanges.next();
347 }
348
349 /**
350 * Implemented as part of MatFormFieldControl.

Callers 1

onContainerClickMethod · 0.95

Calls 4

resolveMethod · 0.80
setFirstItemActiveMethod · 0.80
focusMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected