Skip to content

Commit 427e99a

Browse files
authored
refactor(material/core): clean up focus indicators (#25078)
I skipped over some of the feedback on #25039 in order to get the focus indicator changes merged in quicker. This is a follow-up to address the remaining feedback.
1 parent 2fc61f4 commit 427e99a

File tree

24 files changed

+56
-60
lines changed

24 files changed

+56
-60
lines changed

src/dev-app/theme.scss

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ $candy-app-theme: mat.define-light-theme((
3232
@include experimental.popover-edit-theme($candy-app-theme);
3333

3434
.demo-strong-focus {
35-
// Include base styles for strong focus indicators.
36-
$indicators-config: (border-color: mat.get-color-from-palette($candy-app-primary));
37-
@include mat.strong-focus-indicators($indicators-config);
38-
@include experimental.mdc-strong-focus-indicators($indicators-config);
35+
// Note: we can theme the indicators directly through `strong-focus-indicators` as well.
36+
// Use the theme so we have some coverage over the entire API surface.
37+
@include mat.strong-focus-indicators();
38+
@include mat.strong-focus-indicators-theme($candy-app-theme);
39+
@include experimental.mdc-strong-focus-indicators();
40+
@include experimental.mdc-strong-focus-indicators-theme($candy-app-theme);
3941
}
4042

4143
// Include the alternative theme styles inside of a block with a CSS class. You can make this
@@ -57,9 +59,8 @@ $candy-app-theme: mat.define-light-theme((
5759

5860
// Include the dark theme colors for focus indicators.
5961
&.demo-strong-focus {
60-
$indicators-config: (border-color: mat.get-color-from-palette($dark-primary));
61-
@include mat.strong-focus-indicators($indicators-config);
62-
@include experimental.mdc-strong-focus-indicators($indicators-config);
62+
@include mat.strong-focus-indicators-theme($dark-colors);
63+
@include experimental.mdc-strong-focus-indicators-theme($dark-colors);
6364
}
6465
}
6566

src/material-experimental/mdc-button/button.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@
113113
.mat-mdc-unelevated-button,
114114
.mat-mdc-raised-button {
115115
.mat-mdc-focus-indicator::before {
116-
$default-border-width: mat.$focus-indicators-private-default-border-width;
116+
$default-border-width: mat.$private-strong-focus-indicators-default-border-width;
117117
$border-width: var(--mat-mdc-focus-indicator-border-width, #{$default-border-width});
118118
$offset: calc(#{$border-width} + 2px);
119119
margin: calc(#{$offset} * -1);
120120
}
121121
}
122122

123123
.mat-mdc-outlined-button .mat-mdc-focus-indicator::before {
124-
$default-border-width: mat.$focus-indicators-private-default-border-width;
124+
$default-border-width: mat.$private-strong-focus-indicators-default-border-width;
125125
$border-width: var(--mat-mdc-focus-indicator-border-width, #{$default-border-width});
126126
$offset: calc(#{$border-width} + 3px);
127127
margin: calc(#{$offset} * -1);

src/material-experimental/mdc-button/fab.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
}
6868

6969
.mat-mdc-focus-indicator::before {
70-
$default-border-width: mat.$focus-indicators-private-default-border-width;
70+
$default-border-width: mat.$private-strong-focus-indicators-default-border-width;
7171
$border-width: var(--mat-mdc-focus-indicator-border-width, #{$default-border-width});
7272
$offset: calc(#{$border-width} + 2px);
7373
margin: calc(#{$offset} * -1);

src/material-experimental/mdc-checkbox/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ sass_binary(
4949
],
5050
deps = [
5151
":mdc_checkbox_scss_lib",
52-
"//src/cdk:sass_lib",
5352
"//src/material:sass_lib",
5453
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
5554
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",

src/material-experimental/mdc-chips/chip.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
// For the chip element, default inset/offset values are necessary to ensure that
180180
// the focus indicator is sufficiently contrastive and renders appropriately.
181181
.mat-mdc-focus-indicator::before {
182-
$default-border-width: mat.$focus-indicators-private-default-border-width;
182+
$default-border-width: mat.$private-strong-focus-indicators-default-border-width;
183183
$border-width: var(--mat-mdc-focus-indicator-border-width, #{$default-border-width});
184184
$offset: calc(#{$border-width} + 2px);
185185
margin: calc(#{$offset} * -1);
@@ -196,7 +196,7 @@
196196
}
197197

198198
&::before {
199-
$default-border-width: mat.$focus-indicators-private-default-border-width;
199+
$default-border-width: mat.$private-strong-focus-indicators-default-border-width;
200200
$offset: var(--mat-mdc-focus-indicator-border-width, #{$default-border-width});
201201
margin: calc(#{$offset} * -1);
202202

@@ -228,7 +228,8 @@
228228
}
229229
}
230230

231-
// In the chips the individual actions have focus so we target a different element.
231+
// The chip has multiple focus targets so we have to put the indicator on
232+
// a separate element, rather than on the focusable element itself.
232233
.mat-mdc-chip-action:focus .mat-mdc-focus-indicator::before {
233234
content: '';
234235
}

src/material-experimental/mdc-core/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ sass_binary(
4343
"external/npm/node_modules",
4444
],
4545
deps = [
46-
"//src/cdk:sass_lib",
4746
"//src/material:sass_lib",
4847
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
4948
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",

src/material-experimental/mdc-helpers/_focus-indicators-theme.scss

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22
@use 'sass:map';
33
@use 'sass:meta';
44

5+
$_prefix: 'mat-mdc';
6+
57
// stylelint-disable-next-line material/theme-mixin-api
68
@mixin color($config-or-theme-or-color) {
79
@if meta.type-of($config-or-theme-or-color) == 'color' {
8-
@include mat.focus-indicators-private-private-customize-focus-indicators((
10+
@include mat.private-strong-focus-indicators-customize-focus-indicators((
911
border-color: $config-or-theme-or-color
10-
), 'mat-mdc');
12+
), $_prefix);
1113
}
1214
@else {
1315
$config: mat.get-color-config($config-or-theme-or-color);
1416
$border-color: mat.get-color-from-palette(map.get($config, primary));
15-
@include mat.focus-indicators-private-private-customize-focus-indicators((
17+
@include mat.private-strong-focus-indicators-customize-focus-indicators((
1618
border-color: $border-color
17-
), 'mat-mdc');
19+
), $_prefix);
1820
}
1921
}
2022

2123
// stylelint-disable-next-line material/theme-mixin-api
2224
@mixin theme($theme-or-color-config-or-color) {
2325
@if meta.type-of($theme-or-color-config-or-color) == 'color' {
24-
@include mat.focus-indicators-private-private-customize-focus-indicators((
26+
@include mat.private-strong-focus-indicators-customize-focus-indicators((
2527
border-color: $theme-or-color-config-or-color
26-
), 'mat-mdc');
28+
), $_prefix);
2729
}
2830
@else {
2931
$theme: mat.private-legacy-get-theme($theme-or-color-config-or-color);

src/material-experimental/mdc-helpers/_focus-indicators.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
// Merge default config with user config.
1212
$config: map.merge($default-config, $config);
1313

14-
@include mat.focus-indicators-private-private-customize-focus-indicators($config, 'mat-mdc');
14+
@include mat.private-strong-focus-indicators-customize-focus-indicators($config, 'mat-mdc');
1515
}

src/material-experimental/mdc-list/list.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
// focus/selected/hover state. Hence, we need to have a separate list-item spanning
6060
// element that can be used for strong focus indicators.
6161
.mat-mdc-list-item {
62-
& > .mat-mdc-focus-indicator {
62+
> .mat-mdc-focus-indicator {
6363
@include mat.private-fill();
6464
pointer-events: none;
6565
}

src/material-experimental/mdc-radio/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ sass_binary(
4646
"external/npm/node_modules",
4747
],
4848
deps = [
49-
"//src/cdk:sass_lib",
5049
"//src/material:sass_lib",
5150
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
5251
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",

0 commit comments

Comments
 (0)