Skip to content

refactor(material/tabs): introduce new tokens #26901

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
Apr 10, 2023
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
18 changes: 15 additions & 3 deletions src/material/core/tokens/m2/mat/_tab-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ $prefix: (mat, tab-header);
$is-dark: map.get($config, is-dark);
$foreground: map.get($config, foreground);
$primary: map.get($config, primary);
$inactive-label-text-color: rgba(if($is-dark, #fff, #000), 0.6);
$active-label-text-color: theming.get-color-from-palette($primary, default);
$ripple-color: theming.get-color-from-palette($primary, default);

@return (
ripple-color: theming.get-color-from-palette($primary, default),
disabled-ripple-color: theming.get-color-from-palette($foreground, disabled),
pagination-icon-color: if($is-dark, #fff, #000),

// Note: MDC has equivalents of these tokens, but they lead to much higher selector specificity.
inactive-label-text-color: rgba(if($is-dark, #fff, #000), 0.6),
active-label-text-color: theming.get-color-from-palette($primary, default),
inactive-label-text-color: $inactive-label-text-color,
active-label-text-color: $active-label-text-color,

// Tokens needed to implement the gmat styles. Externally they don't change.
active-ripple-color: $ripple-color,
inactive-ripple-color: $ripple-color,
inactive-focus-label-text-color: $inactive-label-text-color,
inactive-hover-label-text-color: $inactive-label-text-color,
active-focus-label-text-color: $active-label-text-color,
active-hover-label-text-color: $active-label-text-color,
active-focus-indicator-color: $active-label-text-color,
active-hover-indicator-color: $active-label-text-color,
);
}

Expand Down
6 changes: 2 additions & 4 deletions src/material/core/tokens/m2/mdc/_tab-indicator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ $prefix: (mdc, tab-indicator);
@return (
active-indicator-height: 2px,

// =============================================================================================
// = TOKENS NOT USED IN ANGULAR MATERIAL =
// =============================================================================================
active-indicator-shape: null,
// Currently set to zero, but used by the gmat styles to make the indicator rounded.
active-indicator-shape: 0,
);
}

Expand Down
68 changes: 54 additions & 14 deletions src/material/tabs/_tabs-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ $mat-tab-animation-duration: 500ms !default;
}

-webkit-tap-highlight-color: transparent;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-decoration: none;

&.mdc-tab {
// MDC's tabs stretch to fit the header by default, whereas stretching on our current ones
// is an opt-in behavior. Also technically we don't need to combine the two classes, but
// we need the extra specificity to avoid issues with CSS insertion order.
flex-grow: 0;
}

@include token-utils.use-tokens(
tokens-mat-tab-header.$prefix,
tokens-mat-tab-header.get-token-slots()
Expand All @@ -57,28 +66,59 @@ $mat-tab-animation-duration: 500ms !default;
@include token-utils.create-token-slot(letter-spacing, label-text-letter-spacing);
@include token-utils.create-token-slot(line-height, label-text-line-height);
@include token-utils.create-token-slot(font-weight, label-text-weight);
}

&.mdc-tab {
// MDC's tabs stretch to fit the header by default, whereas stretching on our current ones
// is an opt-in behavior. Also technically we don't need to combine the two classes, but
// we need the extra specificity to avoid issues with CSS insertion order.
flex-grow: 0;
&:hover .mdc-tab__text-label {
@include token-utils.create-token-slot(color, inactive-hover-label-text-color);
}

&:not(.mat-mdc-tab-disabled).mdc-tab--active .mdc-tab__text-label {
@include token-utils.use-tokens(
tokens-mat-tab-header.$prefix,
tokens-mat-tab-header.get-token-slots()
) {
&:focus .mdc-tab__text-label {
@include token-utils.create-token-slot(color, inactive-focus-label-text-color);
}

&.mdc-tab--active {
.mdc-tab__text-label {
@include token-utils.create-token-slot(color, active-label-text-color);
}

.mdc-tab__ripple::before,
.mat-ripple-element {
@include token-utils.create-token-slot(background-color, active-ripple-color);
}

&:hover {
.mdc-tab__text-label {
@include token-utils.create-token-slot(color, active-hover-label-text-color);
}

.mdc-tab-indicator__content--underline {
@include token-utils.create-token-slot(border-color, active-hover-indicator-color);
}
}

&:focus {
.mdc-tab__text-label {
@include token-utils.create-token-slot(color, active-focus-label-text-color);
}

.mdc-tab-indicator__content--underline {
@include token-utils.create-token-slot(border-color, active-focus-indicator-color);
}
}
}
}

&.mat-mdc-tab-disabled {
// MDC doesn't support disabled tabs so we need to improvise.
opacity: 0.4;

// We use `pointer-events` to make the element unclickable when it's disabled, rather than
// preventing the default action through JS, because we can't prevent the action reliably
// due to other directives potentially registering their events earlier. This shouldn't cause
// the user to click through, because we always have a header behind the tab. Furthermore, this
// saves us some CSS, because we don't have to add `:not(.mat-mdc-tab-disabled)` to all the
// hover and focus selectors.
pointer-events: none;

@include token-utils.use-tokens(
tokens-mat-tab-header.$prefix,
tokens-mat-tab-header.get-token-slots()
Expand Down Expand Up @@ -107,7 +147,7 @@ $mat-tab-animation-duration: 500ms !default;
tokens-mat-tab-header.$prefix,
tokens-mat-tab-header.get-token-slots()
) {
@include token-utils.create-token-slot(background-color, ripple-color);
@include token-utils.create-token-slot(background-color, inactive-ripple-color);
}
}

Expand Down Expand Up @@ -154,7 +194,7 @@ $mat-tab-animation-duration: 500ms !default;
tokens-mat-tab-header.$prefix,
tokens-mat-tab-header.get-token-slots()
) {
@include token-utils.create-token-slot(background-color, ripple-color);
@include token-utils.create-token-slot(background-color, inactive-ripple-color);
}
}
}
Expand Down Expand Up @@ -202,7 +242,7 @@ $mat-tab-animation-duration: 500ms !default;
tokens-mat-tab-header.$prefix,
tokens-mat-tab-header.get-token-slots()
) {
@include token-utils.create-token-slot(background-color, ripple-color);
@include token-utils.create-token-slot(background-color, inactive-ripple-color);
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/material/tabs/tab-nav-bar/tab-link.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
.mat-mdc-tab-link {
@include tabs-common.tab;

&.mat-mdc-tab-disabled {
// We use `pointer-events` to make the element unclickable when it's disabled, rather than
// preventing the default action through JS, because we can't prevent the action reliably
// due to other directives potentially registering their events earlier. This shouldn't cause
// the user to click through, because we always have a `.mat-tab-links` behind the link.
pointer-events: none;
}

// Note that we only want to target direct descendant tabs.
.mat-mdc-tab-header.mat-mdc-tab-nav-bar-stretch-tabs & {
flex-grow: 1;
Expand Down