Skip to content

Commit 0c5781b

Browse files
committed
fix(material/expansion): center indicator icon in M3 (#28603)
Currently the expansion panel arrow is drawn with borders which makes it difficult to center. It's also problematic in high contrast mode where it renders as a rectangle. We've wanted to fix this for a while, but it breaks a lot of internal screenshot tests (see #10503). These changes resolve the issue for apps using M3 by having two indicators that we toggle using tokens. Fixes #28037. (cherry picked from commit 31102d0)
1 parent c617cd7 commit 0c5781b

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@
467467
_generate-typography-tokens($systems, container-text, body-large),
468468
(
469469
container-shape: _hardcode(12px, $exclude-hardcoded),
470+
legacy-header-indicator-display: _hardcode(none, $exclude-hardcoded),
471+
header-indicator-display: _hardcode(inline-block, $exclude-hardcoded),
470472
container-background-color: map.get($systems, md-sys-color, surface),
471473
container-text-color: map.get($systems, md-sys-color, on-surface),
472474
actions-divider-color: map.get($systems, md-sys-color, outline-variant),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ $prefix: (mat, expansion);
1212
@function get-unthemable-tokens() {
1313
@return (
1414
container-shape: 4px,
15+
legacy-header-indicator-display: inline-block,
16+
header-indicator-display: none,
1517
);
1618
}
1719

src/material/expansion/expansion-panel-header.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@
55
</span>
66

77
@if (_showToggle()) {
8-
<span [@indicatorRotate]="_getExpandedState()" class="mat-expansion-indicator"></span>
8+
<span [@indicatorRotate]="_getExpandedState()" class="mat-expansion-indicator">
9+
<svg
10+
xmlns="http://www.w3.org/2000/svg"
11+
viewBox="0 -960 960 960"
12+
aria-hidden="true"
13+
focusable="false">
14+
<path d="M480-345 240-585l56-56 184 184 184-184 56 56-240 240Z"/>
15+
</svg>
16+
</span>
917
}

src/material/expansion/expansion-panel-header.scss

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,41 @@
140140

141141
// Creates the expansion indicator arrow. Done using ::after
142142
// rather than havingadditional nodes in the template.
143-
.mat-expansion-indicator::after {
144-
border-style: solid;
145-
border-width: 0 2px 2px 0;
146-
content: '';
147-
display: inline-block;
148-
padding: 3px;
149-
transform: rotate(45deg);
150-
vertical-align: middle;
143+
.mat-expansion-indicator {
144+
&::after {
145+
border-style: solid;
146+
border-width: 0 2px 2px 0;
147+
content: '';
148+
display: inline-block;
149+
padding: 3px;
150+
transform: rotate(45deg);
151+
vertical-align: middle;
152+
153+
@include token-utils.use-tokens(
154+
tokens-mat-expansion.$prefix, tokens-mat-expansion.get-token-slots()) {
155+
@include token-utils.create-token-slot(color, header-indicator-color);
156+
@include token-utils.create-token-slot(display, legacy-header-indicator-display,
157+
inline-block);
158+
}
159+
}
151160

152-
@include token-utils.use-tokens(
153-
tokens-mat-expansion.$prefix, tokens-mat-expansion.get-token-slots()) {
154-
@include token-utils.create-token-slot(color, header-indicator-color);
161+
svg {
162+
width: 24px;
163+
height: 24px;
164+
165+
// The SVG icon isn't edge-to-edge so we need to offset
166+
// it slightly so it's aligned correctly horizontally.
167+
margin: 0 -8px;
168+
169+
// Since the container is `display: inline`, we need to set this to center the arrow.
170+
// Ideally we'd make the container `inline-flex`, but that affects M2.
171+
vertical-align: middle;
172+
173+
@include token-utils.use-tokens(
174+
tokens-mat-expansion.$prefix, tokens-mat-expansion.get-token-slots()) {
175+
@include token-utils.create-token-slot(fill, header-indicator-color);
176+
@include token-utils.create-token-slot(display, header-indicator-display, none);
177+
}
155178
}
156179
}
157180

0 commit comments

Comments
 (0)