Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/chips): unable to shift + tab out of a chip set #26727

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/material/chips/chip-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,18 @@ export class MatChipSet
}

/**
* Removes the `tabindex` from the chip grid and resets it back afterwards, allowing the
* user to tab out of it. This prevents the grid from capturing focus and redirecting
* Removes the `tabindex` from the chip set and resets it back afterwards, allowing the
* user to tab out of it. This prevents the set from capturing focus and redirecting
* it back to the first chip, creating a focus trap, if it user tries to tab away.
*/
protected _allowFocusEscape() {
const previousTabIndex = this.tabIndex;

if (this.tabIndex !== -1) {
const previousTabIndex = this.tabIndex;
this.tabIndex = -1;

Promise.resolve().then(() => {
this.tabIndex = previousTabIndex;
this._changeDetectorRef.markForCheck();
});
// Note that this needs to be a `setTimeout`, because a `Promise.resolve`
// doesn't allow enough time for the focus to escape.
setTimeout(() => (this.tabIndex = previousTabIndex));
}
}

Expand Down