Skip to content

Commit 015c350

Browse files
devversionandrewseguin
authored andcommitted
fix(material-experimental/mdc-form-field): add stronger focus indicator in high-contrast mode
Sets up a stronger focus indicator for form fields in high-contrast mode.
1 parent a18d26f commit 015c350

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

src/material-experimental/mdc-form-field/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ sass_library(
7777
srcs = [
7878
"_form-field-density.scss",
7979
"_form-field-focus-overlay.scss",
80+
"_form-field-high-contrast.scss",
8081
"_form-field-native-select.scss",
8182
"_form-field-sizing.scss",
8283
"_form-field-subscript.scss",

src/material-experimental/mdc-form-field/_form-field-density.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
// Mixin that includes the density styles for form fields. MDC provides their own density
3535
// styles for MDC text-field which we cannot use. MDC relies on input elements to stretch
36-
// vertically when the height is reduced as per density scale. This doesn't work for for our
36+
// vertically when the height is reduced as per density scale. This doesn't work for our
3737
// form field since we support custom form field controls without a fixed height. Instead, we
3838
// provide spacing that makes arbitrary controls align as specified in the Material Design
3939
// specification. In order to support density, we need to adjust the vertical spacing to be
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@use '../../cdk/a11y';
2+
3+
@mixin private-form-field-high-contrast() {
4+
$focus-indicator-width: 3px;
5+
$focus-indicator-style: dashed;
6+
7+
// The outline of the `fill` appearance is achieved through a background color
8+
// which won't be visible in high contrast mode. Add an outline to replace it.
9+
.mat-form-field-appearance-fill .mat-mdc-text-field-wrapper {
10+
@include a11y.high-contrast(active, off) {
11+
outline: solid 1px;
12+
}
13+
}
14+
15+
// If a form field with fill appearance is focused, update the outline to be
16+
// dashed and thicker to indicate focus.
17+
.mat-form-field-appearance-fill.mat-focused .mat-mdc-text-field-wrapper {
18+
@include a11y.high-contrast(active, off) {
19+
outline: $focus-indicator-style $focus-indicator-width;
20+
}
21+
}
22+
23+
// For form fields with outline appearance, we unset the outline solid borders
24+
// and show a dashed thick border to indicate focus.
25+
.mat-mdc-form-field.mat-focused .mdc-notched-outline {
26+
@include a11y.high-contrast(active, off) {
27+
.mdc-notched-outline__leading,
28+
.mdc-notched-outline__trailing,
29+
.mdc-notched-outline__notch, {
30+
border: none;
31+
}
32+
33+
border: $focus-indicator-style $focus-indicator-width;
34+
}
35+
}
36+
}

src/material-experimental/mdc-form-field/_mdc-text-field-structure-overrides.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@use 'form-field-sizing';
2-
@use '../../cdk/a11y';
32

43
// Mixin that can be included to override the default MDC text-field
54
// styles to fit our needs. See individual comments for context on why
@@ -113,11 +112,4 @@
113112
content: none;
114113
}
115114

116-
// The outline of the `fill` appearance is achieved through a background color
117-
// which won't be visible in high contrast mode. Add an outline to replace it.
118-
.mat-form-field-appearance-fill .mat-mdc-text-field-wrapper {
119-
@include a11y.high-contrast(active, off) {
120-
outline: solid 1px;
121-
}
122-
}
123115
}

src/material-experimental/mdc-form-field/form-field.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@use './form-field-sizing';
66
@use './form-field-subscript';
77
@use './form-field-focus-overlay';
8+
@use './form-field-high-contrast';
89
@use './form-field-native-select';
910
@use './mdc-text-field-textarea-overrides';
1011
@use './mdc-text-field-structure-overrides';
@@ -23,10 +24,11 @@
2324
@include mdc-text-field-textarea-overrides.private-text-field-textarea-overrides();
2425
@include mdc-text-field-structure-overrides.private-text-field-structure-overrides();
2526

26-
// Include the subscript, focus-overlay and native select styles.
27+
// Include the subscript, focus-overlay, native select and high-contrast styles.
2728
@include form-field-subscript.private-form-field-subscript();
2829
@include form-field-focus-overlay.private-form-field-focus-overlay();
2930
@include form-field-native-select.private-form-field-native-select();
31+
@include form-field-high-contrast.private-form-field-high-contrast();
3032

3133
// Host element of the form-field. It contains the mdc-text-field wrapper
3234
// and the subscript wrapper.

0 commit comments

Comments
 (0)