Skip to content

Commit 9280ad3

Browse files
committed
fix(material/chips): chip grid not re-focusing first item
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)
1 parent 6e937f9 commit 9280ad3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/material/chips/chip-grid.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,14 @@ export class MatChipGrid
340340
// Delay until the next tick, because this can cause a "changed after checked"
341341
// error if the input does something on focus (e.g. opens an autocomplete).
342342
Promise.resolve().then(() => this._chipInput.focus());
343-
} else if (this._chips.length && this._keyManager.activeItemIndex !== 0) {
344-
this._keyManager.setFirstItemActive();
343+
} else {
344+
const activeItem = this._keyManager.activeItem;
345+
346+
if (activeItem) {
347+
activeItem.focus();
348+
} else {
349+
this._keyManager.setFirstItemActive();
350+
}
345351
}
346352

347353
this.stateChanges.next();

0 commit comments

Comments
 (0)