Skip to content

Commit 6ce27af

Browse files
authored
docs: add strong focus indicator instructions to m3 guide (#32177)
Fixes that the default theming guide didn't include the instructions for enabling strong focus indicators.
1 parent 022dba9 commit 6ce27af

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

guides/theming.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,81 @@ structure and CSS classes are considered private implementation details that may
458458
change at any time. CSS variables used by the Angular Material components should
459459
be defined through the `overrides` API instead of defined explicitly.
460460

461+
## Strong focus indicators
462+
463+
By default, most components indicate browser focus by changing their background color as described
464+
by the Material Design specification. This behavior, however, can fall short of accessibility
465+
requirements, such as [WCAG 4.5:1][], which require a stronger indication of browser focus.
466+
467+
Angular Material supports rendering highly visible outlines on focused elements. Applications can
468+
enable these strong focus indicators via two Sass mixins:
469+
`strong-focus-indicators` and `strong-focus-indicators-theme`.
470+
471+
The `strong-focus-indicators` mixin emits structural indicator styles for all components. This mixin
472+
should be included exactly once in an application, similar to the `core` mixin described above.
473+
474+
The `strong-focus-indicators-theme` mixin emits only the indicator's color styles. This mixin should
475+
be included once per theme, similar to the theme mixins described above. Additionally, you can use
476+
this mixin to change the color of the focus indicators in situations in which the default color
477+
would not contrast sufficiently with the background color.
478+
479+
The following example includes strong focus indicator styles in an application alongside the rest of
480+
the custom theme API.
481+
482+
```scss
483+
@use '@angular/material' as mat;
484+
485+
$my-theme: (
486+
color: mat.$violet-palette,
487+
typography: Roboto,
488+
density: 0
489+
);
490+
491+
@include mat.strong-focus-indicators();
492+
493+
html {
494+
color-scheme: light dark;
495+
@include mat.theme($my-theme);
496+
@include mat.strong-focus-indicators-theme($my-theme);
497+
}
498+
```
499+
500+
### Customizing strong focus indicators
501+
502+
You can pass a configuration map to `strong-focus-indicators` to customize the appearance of the
503+
indicators. This configuration includes `border-style`, `border-width`, and `border-radius`.
504+
505+
You also can customize the color of indicators with `strong-focus-indicators-theme`. This mixin
506+
accepts either a theme, as described earlier in this guide, or a CSS color value. When providing a
507+
theme, the indicators will use the default hue of the primary palette.
508+
509+
The following example includes strong focus indicator styles with custom settings alongside the rest
510+
of the custom theme API.
511+
512+
```scss
513+
@use '@angular/material' as mat;
514+
515+
@include mat.strong-focus-indicators((
516+
border-style: dotted,
517+
border-width: 4px,
518+
border-radius: 2px,
519+
));
520+
521+
html {
522+
color-scheme: light dark;
523+
524+
@include mat.theme((
525+
color: mat.$rose-palette,
526+
typography: Roboto,
527+
density: 0
528+
));
529+
530+
@include mat.strong-focus-indicators-theme(orange);
531+
}
532+
```
533+
534+
[WCAG]: https://www.w3.org/WAI/standards-guidelines/wcag/glance/
535+
461536
## Shadow DOM
462537

463538
Angular Material assumes that, by default, all theme styles are loaded as global

0 commit comments

Comments
 (0)