Skip to content

Commit 18e537a

Browse files
committed
fix(material/chips): focus lingering on previous chip (#27559)
Fixes an issue in Safari where clicking on a chip ends up leaving focus on the previously-selected chip. Fixes #27544. (cherry picked from commit 49f6859)
1 parent 3617d59 commit 18e537a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/material/chips/chip-option.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ export class MatChipOption extends MatChip implements OnInit {
170170
}
171171

172172
override _handlePrimaryActionInteraction() {
173-
if (this.selectable && !this.disabled) {
174-
this.toggleSelected(true);
173+
if (!this.disabled) {
174+
// Interacting with the primary action implies that the chip already has focus, however
175+
// there's a bug in Safari where focus ends up lingering on the previous chip (see #27544).
176+
// We work around it by explicitly focusing the primary action of the current chip.
177+
this.focus();
178+
179+
if (this.selectable) {
180+
this.toggleSelected(true);
181+
}
175182
}
176183
}
177184

0 commit comments

Comments
 (0)