Skip to content

Commit a7ce166

Browse files
committed
fix(material/core): default secondary color for focus indicator
1 parent 52720a3 commit a7ce166

File tree

3 files changed

+33
-66
lines changed

3 files changed

+33
-66
lines changed

guides/theming.md

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ body {
5858
}
5959
```
6060

61-
You can also define a convenient set of CSS utility classes that let you apply
61+
You can also define a convenient set of CSS utility classes that let you apply
6262
theme styles from your component templates.
6363

6464
```scss
@@ -103,10 +103,10 @@ distinct accent color to some components.
103103

104104
You can also set the `theme-type` to determine the color values are defined:
105105

106-
* `color-scheme` \- include both light and dark colors using the `light-dark`
107-
CSS color function
108-
* `light` \- only define the light color values
109-
* `dark` \- only define the dark color values
106+
- `color-scheme` \- include both light and dark colors using the `light-dark`
107+
CSS color function
108+
- `light` \- only define the light color values
109+
- `dark` \- only define the dark color values
110110

111111
The `light-dark` CSS color function is
112112
[widely available](https://caniuse.com/?search=light-dark) for all major
@@ -227,18 +227,18 @@ scheme to communicate an application’s hierarchy, state, and brand.
227227
Angular Material provides twelve prebuilt color palettes that can be used for
228228
your application’s theme:
229229

230-
* `$red-palette`
231-
* `$green-palette`
232-
* `$blue-palette`
233-
* `$yellow-palette`
234-
* `$cyan-palette`
235-
* `$magenta-palette`
236-
* `$orange-palette`
237-
* `$chartreuse-palette`
238-
* `$spring-green-palette`
239-
* `$azure-palette`
240-
* `$violet-palette`
241-
* `$rose-palette`
230+
- `$red-palette`
231+
- `$green-palette`
232+
- `$blue-palette`
233+
- `$yellow-palette`
234+
- `$cyan-palette`
235+
- `$magenta-palette`
236+
- `$orange-palette`
237+
- `$chartreuse-palette`
238+
- `$spring-green-palette`
239+
- `$azure-palette`
240+
- `$violet-palette`
241+
- `$rose-palette`
242242

243243
### Custom Color Palettes
244244

@@ -485,46 +485,32 @@ by the Material Design specification. This behavior, however, can fall short of
485485
requirements, such as [WCAG 4.5:1][], which require a stronger indication of browser focus.
486486

487487
Angular Material supports rendering highly visible outlines on focused elements. Applications can
488-
enable these strong focus indicators via two Sass mixins:
489-
`strong-focus-indicators` and `strong-focus-indicators-theme`.
490-
491-
The `strong-focus-indicators` mixin emits structural indicator styles for all components. This mixin
492-
should be included exactly once in an application, similar to the `core` mixin described above.
493-
494-
The `strong-focus-indicators-theme` mixin emits only the indicator's color styles. This mixin should
495-
be included once per theme, similar to the theme mixins described above. Additionally, you can use
496-
this mixin to change the color of the focus indicators in situations in which the default color
497-
would not contrast sufficiently with the background color.
498-
499-
The following example includes strong focus indicator styles in an application alongside the rest of
500-
the custom theme API.
488+
enable these strong focus indicators by calling `mat.strong-focus-indicators()`.
501489

502490
```scss
503491
@use '@angular/material' as mat;
504492

505-
$my-theme: (
506-
color: mat.$violet-palette,
507-
typography: Roboto,
508-
density: 0
509-
);
510-
511-
@include mat.strong-focus-indicators();
512-
513493
html {
514494
color-scheme: light dark;
515-
@include mat.theme($my-theme);
516-
@include mat.strong-focus-indicators-theme($my-theme);
495+
@include mat.theme((
496+
color: mat.$violet-palette,
497+
typography: Roboto,
498+
density: 0
499+
));
500+
@include mat.strong-focus-indicators();
517501
}
518502
```
519503

504+
By default, the focus indicator uses the theme's secondary color, but you can customize this color
505+
by calling the `strong-focus-indicators-theme($color)` mixin. Additionally, you can use
506+
this mixin to change the color of the focus indicators in situations in which the default color
507+
would not contrast sufficiently with the background color.
508+
520509
### Customizing strong focus indicators
521510

522511
You can pass a configuration map to `strong-focus-indicators` to customize the appearance of the
523-
indicators. This configuration includes `border-style`, `border-width`, and `border-radius`.
524-
525-
You also can customize the color of indicators with `strong-focus-indicators-theme`. This mixin
526-
accepts either a theme, as described earlier in this guide, or a CSS color value. When providing a
527-
theme, the indicators will use the default hue of the primary palette.
512+
indicators. This configuration includes `border-color`, `border-style`, `border-width`, and
513+
`border-radius`.
528514

529515
The following example includes strong focus indicator styles with custom settings alongside the rest
530516
of the custom theme API.
@@ -533,22 +519,11 @@ of the custom theme API.
533519
@use '@angular/material' as mat;
534520

535521
@include mat.strong-focus-indicators((
522+
border-color: red,
536523
border-style: dotted,
537524
border-width: 4px,
538525
border-radius: 2px,
539526
));
540-
541-
html {
542-
color-scheme: light dark;
543-
544-
@include mat.theme((
545-
color: mat.$rose-palette,
546-
typography: Roboto,
547-
density: 0
548-
));
549-
550-
@include mat.strong-focus-indicators-theme(orange);
551-
}
552527
```
553528

554529
[WCAG]: https://www.w3.org/WAI/standards-guidelines/wcag/glance/

src/dev-app/theme-m3.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ html {
6060
@include mat.typography-hierarchy($light-theme);
6161

6262
.demo-strong-focus {
63-
// Note: we can theme the indicators directly through `strong-focus-indicators` as well.
64-
// Use the theme so we have some coverage over the entire API surface.
6563
@include mat.strong-focus-indicators();
66-
@include mat.strong-focus-indicators-theme($light-theme);
6764
}
6865

6966
// Include the alternative theme styles inside of a block with a CSS class. You can make this
@@ -80,11 +77,6 @@ body.demo-unicorn-dark-theme {
8077
// @include matx.column-resize-color($dark-theme);
8178
// @include matx.popover-edit-color($dark-theme);
8279
}
83-
84-
// Include the dark theme colors for focus indicators.
85-
&.demo-strong-focus {
86-
@include mat.strong-focus-indicators-color($dark-theme);
87-
}
8880
}
8981

9082
// Create classes for all density scales which are supported by all MDC-based components.

src/material/core/focus-indicators/_private.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $default-border-radius: 4px;
7878
@mixin strong-focus-indicators($config: ()) {
7979
// Default focus indicator config.
8080
$default-config: (
81-
border-color: black,
81+
border-color: var(--mat-sys-secondary, black),
8282
display: block,
8383
);
8484

0 commit comments

Comments
 (0)