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

Method _redirectDestroyedChipFocus

src/material/chips/chip-set.ts:313–337  ·  view source on GitHub ↗

* Finds the next appropriate chip to move focus to, * if the currently-focused chip is destroyed.

()

Source from the content-addressed store, hash-verified

311 * if the currently-focused chip is destroyed.
312 */
313 protected _redirectDestroyedChipFocus() {
314 if (this._lastDestroyedFocusedChipIndex == null) {
315 return;
316 }
317
318 if (this._chips.length) {
319 const newIndex = Math.min(this._lastDestroyedFocusedChipIndex, this._chips.length - 1);
320 const chipToFocus = this._chips.toArray()[newIndex];
321
322 if (chipToFocus.disabled) {
323 // If we're down to one disabled chip, move focus back to the set.
324 if (this._chips.length === 1) {
325 this.focus();
326 } else {
327 this._keyManager.setPreviousItemActive();
328 }
329 } else {
330 chipToFocus.focus();
331 }
332 } else {
333 this.focus();
334 }
335
336 this._lastDestroyedFocusedChipIndex = null;
337 }
338}

Callers 1

_trackChipSetChangesMethod · 0.95

Calls 4

focusMethod · 0.95
setPreviousItemActiveMethod · 0.80
focusMethod · 0.65
minMethod · 0.45

Tested by

no test coverage detected