Skip to content

Commit 52da8b3

Browse files
committed
fix(material/core): avoid solid ripples in buttons (#28717)
The changes from #28664 appear to have caused ripples to be solid in some setups. These changes add a fallback to the old behavior if that's the case. Fixes #28706. (cherry picked from commit 438ff93)
1 parent 79b447e commit 52da8b3

File tree

7 files changed

+27
-7
lines changed

7 files changed

+27
-7
lines changed

src/material/core/tokens/m2/mat/_fab-small.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use 'sass:map';
2+
@use 'sass:meta';
23
@use '@material/ripple/ripple-theme' as mdc-ripple-theme;
34
@use '../../token-utils';
45
@use '../../../theming/theming';
@@ -63,8 +64,9 @@ $prefix: (mat, fab-small);
6364
$foreground-color: null;
6465
$state-layer-color: null;
6566
$ripple-color: null;
67+
$contrast-color: inspection.get-theme-color($theme, $palette-name, default-contrast);
6668

67-
@if (token-utils.$private-is-internal-build) {
69+
@if (token-utils.$private-is-internal-build or meta.type-of($contrast-color) != 'color') {
6870
$is-dark: inspection.get-theme-type($theme) == dark;
6971
$container-color: inspection.get-theme-color($theme, $palette-name);
7072
$contrast-tone: mdc-helpers.variable-safe-contrast-tone($container-color, $is-dark);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use 'sass:map';
2+
@use 'sass:meta';
23
@use '@material/ripple/ripple-theme' as mdc-ripple-theme;
34
@use '../../token-utils';
45
@use '../../../theming/theming';
@@ -63,8 +64,9 @@ $prefix: (mat, fab);
6364
$foreground-color: null;
6465
$state-layer-color: null;
6566
$ripple-color: null;
67+
$contrast-color: inspection.get-theme-color($theme, $palette-name, default-contrast);
6668

67-
@if (token-utils.$private-is-internal-build) {
69+
@if (token-utils.$private-is-internal-build or meta.type-of($contrast-color) != 'color') {
6870
$is-dark: inspection.get-theme-type($theme) == dark;
6971
$container-color: inspection.get-theme-color($theme, $palette-name);
7072
$contrast-tone: mdc-helpers.variable-safe-contrast-tone($container-color, $is-dark);

src/material/core/tokens/m2/mat/_filled-button.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use 'sass:map';
2+
@use 'sass:meta';
23
@use '@material/ripple/ripple-theme' as mdc-ripple-theme;
34
@use '../../token-utils';
45
@use '../../../theming/theming';
@@ -58,10 +59,11 @@ $prefix: (mat, filled-button);
5859
@function private-get-color-palette-color-tokens($theme, $palette-name) {
5960
$state-layer-color: null;
6061
$ripple-color: null;
62+
$contrast-color: inspection.get-theme-color($theme, $palette-name, default-contrast);
6163

6264
// Ideally we would derive all values directly from the theme, but it causes a lot of regressions
6365
// internally. For now we fall back to the old hardcoded behavior only for internal apps.
64-
@if (token-utils.$private-is-internal-build) {
66+
@if (token-utils.$private-is-internal-build or meta.type-of($contrast-color) != 'color') {
6567
$is-dark: inspection.get-theme-type($theme) == dark;
6668
$container-color: inspection.get-theme-color($theme, $palette-name);
6769
$contrast-tone: mdc-helpers.variable-safe-contrast-tone($container-color, $is-dark);

src/material/core/tokens/m2/mat/_icon-button.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ $prefix: (mat, icon-button);
4747
// Generates the mapping for the properties that change based on the button palette color.
4848
@function private-get-color-palette-color-tokens($theme, $palette-name) {
4949
$color: inspection.get-theme-color($theme, $palette-name);
50+
$ripple-opacity: 0.1;
5051

5152
@return (
5253
state-layer-color: $color,
53-
ripple-color: if(meta.type-of($color) == color, rgba($color, 0.1), $color),
54+
ripple-color: if(
55+
meta.type-of($color) == color,
56+
rgba($color, $ripple-opacity),
57+
inspection.get-theme-color($theme, foreground, base, $ripple-opacity)),
5458
);
5559
}
5660

src/material/core/tokens/m2/mat/_outlined-button.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ $prefix: (mat, outlined-button);
5757
// Generates the mapping for the properties that change based on the button palette color.
5858
@function private-get-color-palette-color-tokens($theme, $palette-name) {
5959
$color: inspection.get-theme-color($theme, $palette-name);
60+
$ripple-opacity: 0.1;
6061

6162
@return (
6263
state-layer-color: $color,
63-
ripple-color: if(meta.type-of($color) == color, rgba($color, 0.1), $color),
64+
ripple-color: if(
65+
meta.type-of($color) == color,
66+
rgba($color, $ripple-opacity),
67+
inspection.get-theme-color($theme, foreground, base, $ripple-opacity)),
6468
);
6569
}
6670

src/material/core/tokens/m2/mat/_protected-button.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use 'sass:map';
2+
@use 'sass:meta';
23
@use '@material/ripple/ripple-theme' as mdc-ripple-theme;
34
@use '../../token-utils';
45
@use '../../../theming/theming';
@@ -58,10 +59,11 @@ $prefix: (mat, protected-button);
5859
@function private-get-color-palette-color-tokens($theme, $palette-name) {
5960
$state-layer-color: null;
6061
$ripple-color: null;
62+
$contrast-color: inspection.get-theme-color($theme, $palette-name, default-contrast);
6163

6264
// Ideally we would derive all values directly from the theme, but it causes a lot of regressions
6365
// internally. For now we fall back to the old hardcoded behavior only for internal apps.
64-
@if (token-utils.$private-is-internal-build) {
66+
@if (token-utils.$private-is-internal-build or meta.type-of($contrast-color) != 'color') {
6567
$is-dark: inspection.get-theme-type($theme) == dark;
6668
$container-color: inspection.get-theme-color($theme, $palette-name);
6769
$contrast-tone: mdc-helpers.variable-safe-contrast-tone($container-color, $is-dark);

src/material/core/tokens/m2/mat/_text-button.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ $prefix: (mat, text-button);
6060
// Generates the mapping for the properties that change based on the button palette color.
6161
@function private-get-color-palette-color-tokens($theme, $palette-name) {
6262
$color: inspection.get-theme-color($theme, $palette-name);
63+
$ripple-opacity: 0.1;
6364

6465
@return (
6566
state-layer-color: $color,
66-
ripple-color: if(meta.type-of($color) == color, rgba($color, 0.1), $color),
67+
ripple-color: if(
68+
meta.type-of($color) == color,
69+
rgba($color, $ripple-opacity),
70+
inspection.get-theme-color($theme, foreground, base, $ripple-opacity)),
6771
);
6872
}
6973

0 commit comments

Comments
 (0)