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): show checkmark for selected non-selectable chips #25942

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/material/chips/chip-option.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[attr.aria-selected]="ariaSelected"
[attr.aria-label]="ariaLabel"
role="option">
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic" *ngIf="_hasLeadingGraphic()">
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic">
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
<span class="mdc-evolution-chip__checkmark">
<svg class="mdc-evolution-chip__checkmark-svg" viewBox="-2 -3 30 30" focusable="false">
Expand Down
12 changes: 2 additions & 10 deletions src/material/chips/chip-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ export class MatChipSelectionChange {
styleUrls: ['chip.css'],
inputs: ['color', 'disabled', 'disableRipple', 'tabIndex'],
host: {
'class': 'mat-mdc-chip mat-mdc-chip-option mdc-evolution-chip mdc-evolution-chip--filter',
'class':
'mat-mdc-chip mat-mdc-chip-option mdc-evolution-chip mdc-evolution-chip--filter mdc-evolution-chip--selectable mdc-evolution-chip--with-primary-graphic',
'[class.mat-mdc-chip-selected]': 'selected',
'[class.mat-mdc-chip-multiple]': '_chipListMultiple',
'[class.mat-mdc-chip-disabled]': 'disabled',
'[class.mat-mdc-chip-with-avatar]': 'leadingIcon',
'[class.mdc-evolution-chip--selectable]': 'selectable',
'[class.mdc-evolution-chip--disabled]': 'disabled',
'[class.mdc-evolution-chip--selected]': 'selected',
// This class enables the transition on the checkmark. Usually MDC adds it when selection
Expand All @@ -57,7 +57,6 @@ export class MatChipSelectionChange {
// because they also have an exit animation that we don't care about.
'[class.mdc-evolution-chip--selecting]': '!_animationsDisabled',
'[class.mdc-evolution-chip--with-trailing-action]': '_hasTrailingIcon()',
'[class.mdc-evolution-chip--with-primary-graphic]': '_hasLeadingGraphic()',
'[class.mdc-evolution-chip--with-primary-icon]': 'leadingIcon',
'[class.mdc-evolution-chip--with-avatar]': 'leadingIcon',
'[class.mat-mdc-chip-highlighted]': 'highlighted',
Expand Down Expand Up @@ -163,13 +162,6 @@ export class MatChipOption extends MatChip implements OnInit {
}
}

_hasLeadingGraphic() {
// The checkmark graphic communicates selected state for both single-select and multi-select.
// Include checkmark in single-select to fix a11y issue where selected state is communicated
// visually only using color (#25886).
return this.leadingIcon || this.selectable;
}

_setSelectedState(isSelected: boolean, isUserInput: boolean, emitEvent: boolean) {
if (isSelected !== this.selected) {
this._selected = isSelected;
Expand Down
3 changes: 0 additions & 3 deletions tools/public_api_guard/material/chips.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import * as i0 from '@angular/core';
import * as i11 from '@angular/material/core';
import * as i12 from '@angular/common';
import { InjectionToken } from '@angular/core';
import { MatChipAvatar as MatChipAvatar_2 } from '@angular/material/chips';
import { MatFormField } from '@angular/material/form-field';
import { MatFormFieldControl } from '@angular/material/form-field';
import { MatRipple } from '@angular/material/core';
Expand Down Expand Up @@ -341,8 +340,6 @@ export class MatChipOption extends MatChip implements OnInit {
// (undocumented)
_handlePrimaryActionInteraction(): void;
// (undocumented)
_hasLeadingGraphic(): MatChipAvatar_2;
// (undocumented)
ngOnInit(): void;
select(): void;
get selectable(): boolean;
Expand Down