Skip to content

Commit 09ee075

Browse files
authored
fix(material/list): tokenize active-indicator (#28586)
* fix(material/list): tokenize active-indicator Add active state for MatNavList. Implement active state by implementing 2 tokens under mat prefix. - mat-list-active-indicator-color - mat-list-active-indicator-shape Only affects list items that are anchor tags. Does not intend to make visual changes to M2. * !fixup fix(material/list): tokenize active-indicator
1 parent 11694c3 commit 09ee075

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

src/dev-app/list/list-demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2>Dense lists</h2>
110110
<h2>Nav lists</h2>
111111
<mat-nav-list>
112112
@for (link of links; track link) {
113-
<a mat-list-item [href]="link.href" [activated]="isActivated(link.href)">
113+
<a mat-list-item [href]="link.href" [activated]="isActivated(link)">
114114
{{ link.name }}
115115
</a>
116116
}
@@ -120,7 +120,7 @@ <h2>Nav lists</h2>
120120
}
121121
<mat-nav-list>
122122
@for (link of links; track link; let last = $last) {
123-
<a mat-list-item [href]="link.href" [activated]="isActivated(link.href)">
123+
<a mat-list-item [href]="link.href" [activated]="isActivated(link)">
124124
<mat-icon matListItemIcon>folder</mat-icon>
125125
<span matListItemTitle>{{ link.name }}</span>
126126
</a>

src/dev-app/list/list-demo.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import {MatListModule, MatListOptionTogglePosition} from '@angular/material/list
1313
import {MatIconModule} from '@angular/material/icon';
1414
import {CommonModule} from '@angular/common';
1515

16+
interface Link {
17+
name: string;
18+
href: string;
19+
}
20+
1621
@Component({
1722
selector: 'list-demo',
1823
templateUrl: 'list-demo.html',
@@ -52,7 +57,7 @@ export class ListDemo {
5257
},
5358
];
5459

55-
links: {name: string; href: string}[] = [
60+
links: Link[] = [
5661
{name: 'Inbox', href: '/list#inbox'},
5762
{name: 'Outbox', href: '/list#outbox'},
5863
{name: 'Spam', href: '/list#spam'},
@@ -85,7 +90,7 @@ export class ListDemo {
8590
alert(msg);
8691
}
8792

88-
isActivated(href: string) {
89-
return window.location.href === new URL(href, window.location.href).toString();
93+
isActivated(link: Link) {
94+
return `${window.location.pathname}${window.location.hash}` === link.href;
9095
}
9196
}

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,17 @@
657657
));
658658
}
659659

660+
/// Generates custom tokens for the mat-list.
661+
/// @param {Map} $systems The MDC system tokens
662+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
663+
/// @return {Map} A set of custom tokens for the mat-list
664+
@function list($systems, $exclude-hardcoded) {
665+
@return (
666+
active-indicator-color: map.get($systems, md-sys-color, secondary-container),
667+
active-indicator-shape: map.get($systems, md-sys-shape, corner-full),
668+
);
669+
}
670+
660671
/// Generates custom tokens for the mat-button.
661672
/// @param {Map} $systems The MDC system tokens
662673
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values

src/material-experimental/theming/_m3-tokens.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@
836836
custom-tokens.filled-button($systems, $exclude-hardcoded),
837837
$token-slots
838838
),
839+
_namespace-tokens(
840+
(mat, list),
841+
custom-tokens.list($systems, $exclude-hardcoded),
842+
$token-slots
843+
),
839844
_namespace-tokens(
840845
// Note: in M3 the "protected" button is called "elevated".
841846
(mat, protected-button),

src/material/core/tokens/m2/mat/_list.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ $prefix: (mat, list);
77
// Tokens that can't be configured through Angular Material's current theming API,
88
// but may be in a future version of the theming API.
99
@function get-unthemable-tokens() {
10-
@return ();
10+
@return (
11+
// active indicator themable with M3
12+
active-indicator-color: transparent,
13+
active-indicator-shape: 0,
14+
);
1115
}
1216

1317
// Tokens that can be configured through Angular Material's color theming API.

src/material/list/list.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,12 @@ mat-action-list button {
206206
@include token-utils.create-token-slot(margin-inline-start, list-item-leading-icon-start-space);
207207
@include token-utils.create-token-slot(margin-inline-end, list-item-leading-icon-end-space);
208208
}
209+
210+
a.mdc-list-item.mdc-list-item--activated {
211+
@include token-utils.create-token-slot(background-color, active-indicator-color);
212+
// active-indicator-shape overrides list-item-container-shape
213+
&.mdc-list-item {
214+
@include token-utils.create-token-slot(border-radius, active-indicator-shape);
215+
}
216+
}
209217
}

0 commit comments

Comments
 (0)