Skip to content

Commit 43db4f5

Browse files
authored
refactor(cdk/a11y): Refactor focus indicator theme mixins to match other theme mixins (#22427)
refactor(cdk/a11y): Fix lint warnings cdk(refactor/a11y): Fix lint warnings
1 parent 4bcd76c commit 43db4f5

File tree

5 files changed

+22
-75
lines changed

5 files changed

+22
-75
lines changed

src/dev-app/theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $candy-app-theme: mat.define-light-theme((
6565
@include mdc-slider-theme.color($dark-colors);
6666

6767
// Include the dark theme colors for focus indicators.
68-
.demo-strong-focus {
68+
&.demo-strong-focus {
6969
@include mat.strong-focus-indicators-color($dark-colors);
7070
@include experimental.mdc-strong-focus-indicators-color($dark-colors);
7171
}
Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,21 @@
1-
@use 'sass:meta';
21
@use 'sass:map';
32
@use '../../material/core/theming/theming';
43

5-
// Mixin that applies the border color for the focus indicators.
6-
@mixin _border-color($color) {
7-
.mat-mdc-focus-indicator::before {
8-
border-color: $color;
9-
}
10-
}
11-
124
@mixin color($config-or-theme) {
135
$config: theming.get-color-config($config-or-theme);
146
$border-color: theming.get-color-from-palette(map.get($config, primary));
15-
@include _border-color($border-color);
16-
}
177

18-
/// Mixin that sets the color of the focus indicators.
19-
///
20-
/// @param {color|map} $theme-or-color
21-
/// If theme, focus indicators are set to the primary color of the theme. If
22-
/// color, focus indicators are set to that color.
23-
///
24-
/// @example
25-
/// .demo-dark-theme {
26-
/// @include mat-mdc-strong-focus-indicators-theme($dark-theme-map);
27-
/// }
28-
///
29-
/// @example
30-
/// .demo-red-theme {
31-
/// @include mat-mdc-strong-focus-indicators-theme(#f00);
32-
/// }
33-
// stylelint-disable-next-line material/theme-mixin-api
34-
@mixin theme($theme-or-color) {
35-
@if meta.type-of($theme-or-color) != 'map' {
36-
@include _border-color($theme-or-color);
8+
.mat-mdc-focus-indicator::before {
9+
border-color: $border-color;
3710
}
38-
@else {
39-
$theme: theming.private-legacy-get-theme($theme-or-color);
40-
@include theming.private-check-duplicate-theme-styles($theme,
41-
'mat-mdc-strong-focus-indicators') {
42-
$color: theming.get-color-config($theme);
43-
@if $color != null {
44-
@include color($color);
45-
}
11+
}
12+
13+
@mixin theme($theme-or-color-config) {
14+
$theme: theming.private-legacy-get-theme($theme-or-color-config);
15+
@include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-focus-indicators') {
16+
$color: theming.get-color-config($theme);
17+
@if $color != null {
18+
@include color($color);
4619
}
4720
}
4821
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@forward '../../material/core/focus-indicators/focus-indicators.import';
22
@forward 'focus-indicators' hide strong-focus-indicators;
33
@forward 'focus-indicators-theme' hide color, theme;
4-
@forward 'focus-indicators' as mat-mdc-* hide mat-mdc-strong-focus-indicators-border-color;
4+
@forward 'focus-indicators' as mat-mdc-*;
55
@forward 'focus-indicators-theme' as mat-mdc-strong-focus-indicators-*;
66

77
@import '../../material/core/theming/theming';
Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,21 @@
1-
@use 'sass:meta';
21
@use 'sass:map';
32
@use '../theming/theming';
43

54
@mixin color($config-or-theme) {
65
$config: theming.get-color-config($config-or-theme);
76
$border-color: theming.get-color-from-palette(map.get($config, primary));
8-
@include _border-color($border-color);
9-
}
107

11-
/// Mixin that sets the color of the focus indicators.
12-
///
13-
/// @param {color|map} $theme-or-color
14-
/// If theme, focus indicators are set to the primary color of the theme. If
15-
/// color, focus indicators are set to that color.
16-
///
17-
/// @example
18-
/// .demo-dark-theme {
19-
/// @include mat-strong-focus-indicators-theme($dark-theme-map);
20-
/// }
21-
///
22-
/// @example
23-
/// .demo-red-theme {
24-
/// @include mat-strong-focus-indicators-theme(#f00);
25-
/// }
26-
// stylelint-disable-next-line material/theme-mixin-api
27-
@mixin theme($theme-or-color) {
28-
@if meta.type-of($theme-or-color) != 'map' {
29-
@include _border-color($theme-or-color);
30-
}
31-
@else {
32-
$theme: theming.private-legacy-get-theme($theme-or-color);
33-
@include theming.private-check-duplicate-theme-styles($theme, 'mat-strong-focus-indicators') {
34-
$color: theming.get-color-config($theme);
35-
@if $color != null {
36-
@include color($color);
37-
}
38-
}
8+
.mat-focus-indicator::before {
9+
border-color: $border-color;
3910
}
4011
}
4112

42-
// Mixin that applies the border color for the focus indicators.
43-
@mixin _border-color($color) {
44-
.mat-focus-indicator::before {
45-
border-color: $color;
13+
@mixin theme($theme-or-color-config) {
14+
$theme: theming.private-legacy-get-theme($theme-or-color-config);
15+
@include theming.private-check-duplicate-theme-styles($theme, 'mat-focus-indicators') {
16+
$color: theming.get-color-config($theme);
17+
@if $color != null {
18+
@include color($color);
19+
}
4620
}
4721
}

src/material/core/focus-indicators/_focus-indicators.import.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $mat-white-6-opacity, $mat-white-87-opacity;
1515
@forward 'focus-indicators' hide private-strong-focus-indicators-positioning,
1616
strong-focus-indicators;
1717
@forward 'focus-indicators-theme' hide color, theme;
18-
@forward 'focus-indicators' as mat-* hide mat-strong-focus-indicators-border-color;
18+
@forward 'focus-indicators' as mat-*;
1919
@forward 'focus-indicators-theme' as mat-strong-focus-indicators-*;
2020

2121
@import '../theming/theming';

0 commit comments

Comments
 (0)