MCPcopy Index your code
hub / github.com/angular/components / _setUpFocusManagement

Method _setUpFocusManagement

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

Sets up the chip set's focus management logic.

()

Source from the content-addressed store, hash-verified

226
227 /** Sets up the chip set's focus management logic. */
228 private _setUpFocusManagement() {
229 // Create a flat `QueryList` containing the actions of all of the chips.
230 // This allows us to navigate both within the chip and move to the next/previous
231 // one using the existing `ListKeyManager`.
232 this._chips.changes.pipe(startWith(this._chips)).subscribe((chips: QueryList<MatChip>) => {
233 const actions: MatChipAction[] = [];
234 chips.forEach(chip => chip._getActions().forEach(action => actions.push(action)));
235 this._chipActions.reset(actions);
236 this._chipActions.notifyOnChanges();
237 });
238
239 this._keyManager = new FocusKeyManager(this._chipActions)
240 .withVerticalOrientation()
241 .withHorizontalOrientation(this._dir ? this._dir.value : 'ltr')
242 .withHomeAndEnd()
243 .skipPredicate(action => this._skipPredicate(action));
244
245 // Keep the manager active index in sync so that navigation picks
246 // up from the current chip if the user clicks into the list directly.
247 this.chipFocusChanges.pipe(takeUntil(this._destroyed)).subscribe(({chip}) => {
248 const action = chip._getSourceAction(document.activeElement as Element);
249
250 if (action) {
251 this._keyManager.updateActiveItem(action);
252 }
253 });
254
255 this._dir?.change
256 .pipe(takeUntil(this._destroyed))
257 .subscribe(direction => this._keyManager.withHorizontalOrientation(direction));
258 }
259
260 /**
261 * Determines if key manager should avoid putting a given chip action in the tab index. Skip

Callers 1

ngAfterViewInitMethod · 0.95

Calls 10

_skipPredicateMethod · 0.95
_getActionsMethod · 0.80
skipPredicateMethod · 0.80
withHomeAndEndMethod · 0.80
_getSourceActionMethod · 0.80
updateActiveItemMethod · 0.80
pushMethod · 0.65
resetMethod · 0.65

Tested by

no test coverage detected