Skip to content

Commit 168619b

Browse files
authored
fix(material/chips): unable to shift + tab out of a chip set (#26727)
Fixes that it wasn't possible for the user to use shift + tab to move out of a chip set. We had some logic to handle it already, but it was resetting the tabindex before focus has a chance to escape. Fixes #26698.
1 parent f0363d3 commit 168619b

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/material/chips/chip-set.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,18 @@ export class MatChipSet
189189
}
190190

191191
/**
192-
* Removes the `tabindex` from the chip grid and resets it back afterwards, allowing the
193-
* user to tab out of it. This prevents the grid from capturing focus and redirecting
192+
* Removes the `tabindex` from the chip set and resets it back afterwards, allowing the
193+
* user to tab out of it. This prevents the set from capturing focus and redirecting
194194
* it back to the first chip, creating a focus trap, if it user tries to tab away.
195195
*/
196196
protected _allowFocusEscape() {
197-
const previousTabIndex = this.tabIndex;
198-
199197
if (this.tabIndex !== -1) {
198+
const previousTabIndex = this.tabIndex;
200199
this.tabIndex = -1;
201200

202-
Promise.resolve().then(() => {
203-
this.tabIndex = previousTabIndex;
204-
this._changeDetectorRef.markForCheck();
205-
});
201+
// Note that this needs to be a `setTimeout`, because a `Promise.resolve`
202+
// doesn't allow enough time for the focus to escape.
203+
setTimeout(() => (this.tabIndex = previousTabIndex));
206204
}
207205
}
208206

0 commit comments

Comments
 (0)