Skip to content

Commit

Permalink
fix(material/chips): chip grid not re-focusing first item
Browse files Browse the repository at this point in the history
There was some logic that assumed that if a chip is the active item in the key manager, it must have focus. That's incorrect since the active item isn't reset on blur. This prevented the chip grid from re-focusing the first chip when the user tabs into it a second time.

These changes add a `focus` call whenever the grid receives focus.

Fixes #29785.

(cherry picked from commit 2861a30)
  • Loading branch information
crisbeto committed Sep 30, 2024
1 parent 6e937f9 commit 9280ad3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/material/chips/chip-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,14 @@ export class MatChipGrid
// Delay until the next tick, because this can cause a "changed after checked"
// error if the input does something on focus (e.g. opens an autocomplete).
Promise.resolve().then(() => this._chipInput.focus());
} else if (this._chips.length && this._keyManager.activeItemIndex !== 0) {
this._keyManager.setFirstItemActive();
} else {
const activeItem = this._keyManager.activeItem;

if (activeItem) {
activeItem.focus();
} else {
this._keyManager.setFirstItemActive();
}
}

this.stateChanges.next();
Expand Down

0 comments on commit 9280ad3

Please sign in to comment.