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/expansion): center indicator icon in M3 #28603

Merged
merged 1 commit into from
Feb 21, 2024
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: 2 additions & 0 deletions src/material-experimental/theming/_custom-tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@
_generate-typography-tokens($systems, container-text, body-large),
(
container-shape: _hardcode(12px, $exclude-hardcoded),
legacy-header-indicator-display: _hardcode(none, $exclude-hardcoded),
header-indicator-display: _hardcode(inline-block, $exclude-hardcoded),
container-background-color: map.get($systems, md-sys-color, surface),
container-text-color: map.get($systems, md-sys-color, on-surface),
actions-divider-color: map.get($systems, md-sys-color, outline-variant),
Expand Down
2 changes: 2 additions & 0 deletions src/material/core/tokens/m2/mat/_expansion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ $prefix: (mat, expansion);
@function get-unthemable-tokens() {
@return (
container-shape: 4px,
legacy-header-indicator-display: inline-block,
header-indicator-display: none,
);
}

Expand Down
10 changes: 9 additions & 1 deletion src/material/expansion/expansion-panel-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
</span>

@if (_showToggle()) {
<span [@indicatorRotate]="_getExpandedState()" class="mat-expansion-indicator"></span>
<span [@indicatorRotate]="_getExpandedState()" class="mat-expansion-indicator">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 -960 960 960"
aria-hidden="true"
focusable="false">
<path d="M480-345 240-585l56-56 184 184 184-184 56 56-240 240Z"/>
</svg>
</span>
}
45 changes: 34 additions & 11 deletions src/material/expansion/expansion-panel-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,41 @@

// Creates the expansion indicator arrow. Done using ::after
// rather than havingadditional nodes in the template.
.mat-expansion-indicator::after {
border-style: solid;
border-width: 0 2px 2px 0;
content: '';
display: inline-block;
padding: 3px;
transform: rotate(45deg);
vertical-align: middle;
.mat-expansion-indicator {
&::after {
border-style: solid;
border-width: 0 2px 2px 0;
content: '';
display: inline-block;
padding: 3px;
transform: rotate(45deg);
vertical-align: middle;

@include token-utils.use-tokens(
tokens-mat-expansion.$prefix, tokens-mat-expansion.get-token-slots()) {
@include token-utils.create-token-slot(color, header-indicator-color);
@include token-utils.create-token-slot(display, legacy-header-indicator-display,
inline-block);
}
}

@include token-utils.use-tokens(
tokens-mat-expansion.$prefix, tokens-mat-expansion.get-token-slots()) {
@include token-utils.create-token-slot(color, header-indicator-color);
svg {
width: 24px;
height: 24px;

// The SVG icon isn't edge-to-edge so we need to offset
// it slightly so it's aligned correctly horizontally.
margin: 0 -8px;

// Since the container is `display: inline`, we need to set this to center the arrow.
// Ideally we'd make the container `inline-flex`, but that affects M2.
vertical-align: middle;

@include token-utils.use-tokens(
tokens-mat-expansion.$prefix, tokens-mat-expansion.get-token-slots()) {
@include token-utils.create-token-slot(fill, header-indicator-color);
@include token-utils.create-token-slot(display, header-indicator-display, none);
}
}
}

Expand Down
Loading