Skip to content

Commit 95ade49

Browse files
committed
docs(material/theming): document strong focus indicators
This adds documentation for strong focus indicators as part of the theming guide. This feature has been "soft launched" inside Google, but hasn't been documented for widespread adoption. At this stage, I'm confident enough in the stability of the feature to document it for public usage.
1 parent 5fd431f commit 95ade49

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

guides/theming.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,83 @@ $my-palette: mat.define-palette(mat.$indigo-palette);
367367
}
368368
```
369369

370+
## Strong focus indicators
371+
372+
By default, most components indicate browser focus by changing their background color as prescribed
373+
by the Material Design specification. This behavior, however, can fall short of accessibility
374+
requirements, such as [WCAG][], which require a stronger indication of browser focus.
375+
376+
Angular Material supports rendering highly visible outlines on focused elements. Applications can
377+
enable these strong focus indicators via two Sass mixins:
378+
`strong-focus-indicators` and `strong-focus-indicators-theme`.
379+
380+
The `strong-focus-indicators` mixin emits structal indicator styles for all components. This mixin
381+
should be included exactly once in an application, similar to the `core` mixin described above.
382+
383+
The `strong-focus-indicators-theme` mixin emits only the indicator's color styles. This mixin should
384+
be included once per theme, similar to the theme mixins described above.
385+
386+
The following example includes strong focus indicator styles in an application alongside the rest of
387+
the custom theme API.
388+
389+
```scss
390+
@use '~@angular/material' as mat;
391+
392+
@include mat.core();
393+
@include mat.strong-focus-indicators();
394+
395+
$my-primary: mat.define-palette(mat.$indigo-palette, 500);
396+
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
397+
398+
$my-theme: mat.define-light-theme((
399+
color: (
400+
primary: $my-primary,
401+
accent: $my-accent,
402+
)
403+
));
404+
405+
@include mat.all-component-themes($my-theme);
406+
@include mat.strong-focus-indicators-theme($my-theme);
407+
```
408+
409+
### Customizing strong focus indicators
410+
411+
You can pass a configuration map to `strong-focus-indicators` to customize the appearance of the
412+
indicators. This configuration includes `border-style`, `border-width`, and `border-radius`.
413+
414+
You also can customize the color of indicators with `strong-focus-indicators-theme`. This mixin
415+
accepts either a theme, as described earlier in this guide, or a CSS color value. When providing a
416+
theme, the indicators will use the default hue of the primary palette.
417+
418+
The following example includes strong focus indicator styles with custom settings alongside the rest
419+
of the custom theme API.
420+
421+
```scss
422+
@use '~@angular/material' as mat;
423+
424+
@include mat.core();
425+
@include mat.strong-focus-indicators((
426+
border-style: dotted,
427+
border-width: 4px,
428+
border-radius: 2px,
429+
));
430+
431+
$my-primary: mat.define-palette(mat.$indigo-palette, 500);
432+
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
433+
434+
$my-theme: mat.define-light-theme((
435+
color: (
436+
primary: $my-primary,
437+
accent: $my-accent,
438+
)
439+
));
440+
441+
@include mat.all-component-themes($my-theme);
442+
@include mat.strong-focus-indicators-theme(purple);
443+
```
444+
445+
[WCAG]: https://www.w3.org/WAI/standards-guidelines/wcag/glance/
446+
370447
## Theming and style encapsulation
371448

372449
Angular Material assumes that, by default, all theme styles are loaded as global CSS. If you want

0 commit comments

Comments
 (0)