Skip to content

Commit 871f8f2

Browse files
authored
fix(material/chips): show checkmark for selected non-selectable chips (#25942)
Fixes that chips that were selected programmatically, but were set as `selectable="false"` weren't showing the checkmark as intended in #25890. Also removes some of the logic now that we can assume that the checkmark will always be present.
1 parent 70fdadf commit 871f8f2

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

src/material/chips/chip-option.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[attr.aria-selected]="ariaSelected"
1313
[attr.aria-label]="ariaLabel"
1414
role="option">
15-
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic" *ngIf="_hasLeadingGraphic()">
15+
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic">
1616
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
1717
<span class="mdc-evolution-chip__checkmark">
1818
<svg class="mdc-evolution-chip__checkmark-svg" viewBox="-2 -3 30 30" focusable="false">

src/material/chips/chip-option.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ export class MatChipSelectionChange {
4343
styleUrls: ['chip.css'],
4444
inputs: ['color', 'disabled', 'disableRipple', 'tabIndex'],
4545
host: {
46-
'class': 'mat-mdc-chip mat-mdc-chip-option mdc-evolution-chip mdc-evolution-chip--filter',
46+
'class':
47+
'mat-mdc-chip mat-mdc-chip-option mdc-evolution-chip mdc-evolution-chip--filter mdc-evolution-chip--selectable mdc-evolution-chip--with-primary-graphic',
4748
'[class.mat-mdc-chip-selected]': 'selected',
4849
'[class.mat-mdc-chip-multiple]': '_chipListMultiple',
4950
'[class.mat-mdc-chip-disabled]': 'disabled',
5051
'[class.mat-mdc-chip-with-avatar]': 'leadingIcon',
51-
'[class.mdc-evolution-chip--selectable]': 'selectable',
5252
'[class.mdc-evolution-chip--disabled]': 'disabled',
5353
'[class.mdc-evolution-chip--selected]': 'selected',
5454
// This class enables the transition on the checkmark. Usually MDC adds it when selection
@@ -57,7 +57,6 @@ export class MatChipSelectionChange {
5757
// because they also have an exit animation that we don't care about.
5858
'[class.mdc-evolution-chip--selecting]': '!_animationsDisabled',
5959
'[class.mdc-evolution-chip--with-trailing-action]': '_hasTrailingIcon()',
60-
'[class.mdc-evolution-chip--with-primary-graphic]': '_hasLeadingGraphic()',
6160
'[class.mdc-evolution-chip--with-primary-icon]': 'leadingIcon',
6261
'[class.mdc-evolution-chip--with-avatar]': 'leadingIcon',
6362
'[class.mat-mdc-chip-highlighted]': 'highlighted',
@@ -163,13 +162,6 @@ export class MatChipOption extends MatChip implements OnInit {
163162
}
164163
}
165164

166-
_hasLeadingGraphic() {
167-
// The checkmark graphic communicates selected state for both single-select and multi-select.
168-
// Include checkmark in single-select to fix a11y issue where selected state is communicated
169-
// visually only using color (#25886).
170-
return this.leadingIcon || this.selectable;
171-
}
172-
173165
_setSelectedState(isSelected: boolean, isUserInput: boolean, emitEvent: boolean) {
174166
if (isSelected !== this.selected) {
175167
this._selected = isSelected;

tools/public_api_guard/material/chips.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import * as i0 from '@angular/core';
2828
import * as i11 from '@angular/material/core';
2929
import * as i12 from '@angular/common';
3030
import { InjectionToken } from '@angular/core';
31-
import { MatChipAvatar as MatChipAvatar_2 } from '@angular/material/chips';
3231
import { MatFormField } from '@angular/material/form-field';
3332
import { MatFormFieldControl } from '@angular/material/form-field';
3433
import { MatRipple } from '@angular/material/core';
@@ -341,8 +340,6 @@ export class MatChipOption extends MatChip implements OnInit {
341340
// (undocumented)
342341
_handlePrimaryActionInteraction(): void;
343342
// (undocumented)
344-
_hasLeadingGraphic(): MatChipAvatar_2;
345-
// (undocumented)
346343
ngOnInit(): void;
347344
select(): void;
348345
get selectable(): boolean;

0 commit comments

Comments
 (0)