Skip to content

fix(material/chips): highlighted not working in M3 #29001

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

Merged
merged 1 commit into from
May 5, 2024
Merged
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
35 changes: 30 additions & 5 deletions src/material/chips/chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,35 @@
@include mdc-chip-theme.theme-styles($mdc-chip-token-slots);
}

// The highlighted attribute is used to make the chip appear as selected on-demand,
// aside from showing the selected indicator. We achieve this by re-mapping the base
// tokens to the highlighted ones. Note that we only need to do this for the tokens
// that we don't re-implement ourselves below.
// TODO(crisbeto): with some future refactors we may be able to clean this up.
.mat-mdc-chip-highlighted {
@include token-utils.use-tokens(tokens-mdc-chip.$prefix, $mdc-chip-token-slots) {
$highlighted-remapped-tokens: (
with-icon-icon-color: with-icon-selected-icon-color,
elevated-container-color: elevated-selected-container-color,
label-text-color: selected-label-text-color,
outline-width: flat-selected-outline-width,
);

@each $selected, $base in $highlighted-remapped-tokens {
#{token-utils.get-token-variable($selected)}: var(token-utils.get-token-variable($base));
}
}
}

// Add additional slots for the MDC chip tokens, needed in Angular Material.
$disabled-trailing-icon-opacity: 1;

@include token-utils.use-tokens(tokens-mdc-chip.$prefix, $mdc-chip-token-slots) {
.mat-mdc-chip-focus-overlay {
@include token-utils.create-token-slot(background, focus-state-layer-color);

.mat-mdc-chip-selected & {
.mat-mdc-chip-selected &,
.mat-mdc-chip-highlighted & {
@include token-utils.create-token-slot(background, selected-focus-state-layer-color);
}

Expand All @@ -38,7 +59,8 @@
@include token-utils.create-token-slot(opacity, hover-state-layer-opacity);
}

.mat-mdc-chip-selected:hover & {
.mat-mdc-chip-selected:hover,
.mat-mdc-chip-highlighted:hover & {
@include token-utils.create-token-slot(background, selected-hover-state-layer-color);
@include token-utils.create-token-slot(opacity, selected-hover-state-layer-opacity);
}
Expand All @@ -48,7 +70,8 @@
@include token-utils.create-token-slot(opacity, focus-state-layer-opacity);
}

.mat-mdc-chip-selected.cdk-focused & {
.mat-mdc-chip-selected.cdk-focused &,
.mat-mdc-chip-highlighted.cdk-focused & {
@include token-utils.create-token-slot(background, selected-focus-state-layer-color);
@include token-utils.create-token-slot(opacity, selected-focus-state-layer-opacity);
}
Expand Down Expand Up @@ -79,7 +102,8 @@
@include token-utils.create-token-slot(opacity, disabled-container-opacity);
}

&.mdc-evolution-chip--selected {
&.mdc-evolution-chip--selected,
&.mat-mdc-chip-highlighted {
.mdc-evolution-chip__icon--trailing {
@include token-utils.create-token-slot(color, selected-trailing-icon-color);
}
Expand Down Expand Up @@ -110,7 +134,8 @@
}
}

.mat-mdc-chip-selected .mat-mdc-chip-remove::after {
.mat-mdc-chip-selected .mat-mdc-chip-remove::after,
.mat-mdc-chip-highlighted .mat-mdc-chip-remove::after {
@include token-utils.create-token-slot(
background, selected-trailing-action-state-layer-color);
}
Expand Down