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

Method focus

src/material/chips/chip-grid.ts:325–349  ·  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

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