-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(material/theming): document strong focus indicators #22374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,85 @@ $my-palette: mat.define-palette(mat.$indigo-palette); | |
} | ||
``` | ||
|
||
## Strong focus indicators | ||
|
||
By default, most components indicate browser focus by changing their background color as described | ||
by the Material Design specification. This behavior, however, can fall short of accessibility | ||
requirements, such as [WCAG][], which require a stronger indication of browser focus. | ||
jelbourn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Angular Material supports rendering highly visible outlines on focused elements. Applications can | ||
enable these strong focus indicators via two Sass mixins: | ||
`strong-focus-indicators` and `strong-focus-indicators-theme`. | ||
|
||
The `strong-focus-indicators` mixin emits structal indicator styles for all components. This mixin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is "structal" supposed to be "structural" or "strong"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did intent to say "structural" versus the color styles from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Structural makes sense, thanks! |
||
should be included exactly once in an application, similar to the `core` mixin described above. | ||
|
||
The `strong-focus-indicators-theme` mixin emits only the indicator's color styles. This mixin should | ||
be included once per theme, similar to the theme mixins described above. Additionally, you can use | ||
this mixin to change the color of the focus indicators in situations in which the default color | ||
would not contrast sufficiently with the background color. | ||
|
||
The following example includes strong focus indicator styles in an application alongside the rest of | ||
the custom theme API. | ||
|
||
```scss | ||
@use '~@angular/material' as mat; | ||
|
||
@include mat.core(); | ||
@include mat.strong-focus-indicators(); | ||
|
||
$my-primary: mat.define-palette(mat.$indigo-palette, 500); | ||
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400); | ||
|
||
$my-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $my-primary, | ||
accent: $my-accent, | ||
) | ||
)); | ||
|
||
@include mat.all-component-themes($my-theme); | ||
@include mat.strong-focus-indicators-theme($my-theme); | ||
``` | ||
|
||
### Customizing strong focus indicators | ||
|
||
You can pass a configuration map to `strong-focus-indicators` to customize the appearance of the | ||
indicators. This configuration includes `border-style`, `border-width`, and `border-radius`. | ||
|
||
You also can customize the color of indicators with `strong-focus-indicators-theme`. This mixin | ||
accepts either a theme, as described earlier in this guide, or a CSS color value. When providing a | ||
theme, the indicators will use the default hue of the primary palette. | ||
|
||
The following example includes strong focus indicator styles with custom settings alongside the rest | ||
of the custom theme API. | ||
|
||
```scss | ||
@use '~@angular/material' as mat; | ||
|
||
@include mat.core(); | ||
@include mat.strong-focus-indicators(( | ||
border-style: dotted, | ||
border-width: 4px, | ||
border-radius: 2px, | ||
)); | ||
|
||
$my-primary: mat.define-palette(mat.$indigo-palette, 500); | ||
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400); | ||
|
||
$my-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $my-primary, | ||
accent: $my-accent, | ||
) | ||
)); | ||
|
||
@include mat.all-component-themes($my-theme); | ||
@include mat.strong-focus-indicators-theme(purple); | ||
``` | ||
|
||
[WCAG]: https://www.w3.org/WAI/standards-guidelines/wcag/glance/ | ||
|
||
## Theming and style encapsulation | ||
|
||
Angular Material assumes that, by default, all theme styles are loaded as global CSS. If you want | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we can add when it can fall short, and if it does universally, why wouldn't I just always enable strong focus indication if it's a known shortcoming? When would I require a stronger indication of browser focus? Maybe just a visual example of what this looks like would be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC WCAG 2.2 implies that strong focus indicators are necessary but doesn't outright say it. Google'e internal requirements don't require it today, but probably will in the next year or so. We don't do this by default because it's not included in the Material Design spec. I've communicated to MD that it's a priority for us, but haven't seen any movement on it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense this is in the main theming guide then and likely should be built in!