Skip to content

Commit 2861a30

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 angular#29785.
1 parent ff3d342 commit 2861a30

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
@@ -336,8 +336,14 @@ export class MatChipGrid
336336
// Delay until the next tick, because this can cause a "changed after checked"
337337
// error if the input does something on focus (e.g. opens an autocomplete).
338338
Promise.resolve().then(() => this._chipInput.focus());
339-
} else if (this._chips.length && this._keyManager.activeItemIndex !== 0) {
340-
this._keyManager.setFirstItemActive();
339+
} else {
340+
const activeItem = this._keyManager.activeItem;
341+
342+
if (activeItem) {
343+
activeItem.focus();
344+
} else {
345+
this._keyManager.setFirstItemActive();
346+
}
341347
}
342348

343349
this.stateChanges.next();

0 commit comments

Comments
 (0)