Skip to content

Commit 0a39595

Browse files
crisbetojelbourn
authored andcommitted
fix(form-field): inaccessible in high contrast mode (#11736)
Fixes the following issues that made the form field hard to use in high contrast mode: * Hides the infix border in high contrast mode so it doesn't render as solid yellow/white bars. * Fixes the underlines and underline ripples not being rendered. * Fixes the `fill` appearance blending in with the background. Fixes #6257. Fixes #6383. Fixes #9009.
1 parent bf88702 commit 0a39595

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

src/lib/form-field/form-field-fill.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/vendor-prefixes';
3-
3+
@import '../../cdk/a11y/a11y';
44

55
// Styles that only apply to the fill appearance of the form-field.
66

@@ -27,6 +27,10 @@ $mat-form-field-fill-subscript-padding:
2727
border-radius: $mat-form-field-fill-border-radius $mat-form-field-fill-border-radius 0 0;
2828
padding: $mat-form-field-fill-line-spacing $mat-form-field-fill-side-padding 0
2929
$mat-form-field-fill-side-padding;
30+
31+
@include cdk-high-contrast {
32+
outline: solid 1px;
33+
}
3034
}
3135

3236
.mat-form-field-underline::before {
@@ -41,6 +45,11 @@ $mat-form-field-fill-subscript-padding:
4145
.mat-form-field-ripple {
4246
bottom: 0;
4347
height: $mat-form-field-fill-underline-ripple-height;
48+
49+
@include cdk-high-contrast {
50+
height: 0;
51+
border-top: solid $mat-form-field-fill-underline-ripple-height;
52+
}
4453
}
4554

4655
// Note that we need this specific of a selector because we don't want

src/lib/form-field/form-field-legacy.scss

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/vendor-prefixes';
3+
@import '../../cdk/a11y/a11y';
34

45

56
// Styles that only apply to the legacy appearance of the form-field.
@@ -36,11 +37,22 @@ $mat-form-field-legacy-underline-height: 1px !default;
3637
// The ripple is the blue animation coming on top of it.
3738
.mat-form-field-underline {
3839
height: $mat-form-field-legacy-underline-height;
40+
41+
@include cdk-high-contrast {
42+
height: 0;
43+
border-top: solid $mat-form-field-legacy-underline-height;
44+
}
3945
}
4046

4147
.mat-form-field-ripple {
48+
$height: $mat-form-field-legacy-underline-height * 2;
4249
top: 0;
43-
height: $mat-form-field-legacy-underline-height * 2;
50+
height: $height;
51+
52+
@include cdk-high-contrast {
53+
height: 0;
54+
border-top: solid $height;
55+
}
4456
}
4557

4658
&.mat-form-field-disabled .mat-form-field-underline {

src/lib/form-field/form-field-standard.scss

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/vendor-prefixes';
3+
@import '../../cdk/a11y/a11y';
34

45

56
// Styles that only apply to the standard appearance of the form-field.
@@ -20,11 +21,22 @@ $mat-form-field-standard-padding-top: 0.75em !default;
2021
// The ripple is the blue animation coming on top of it.
2122
.mat-form-field-underline {
2223
height: $mat-form-field-standard-underline-height;
24+
25+
@include cdk-high-contrast {
26+
height: 0;
27+
border-top: solid $mat-form-field-standard-underline-height;
28+
}
2329
}
2430

2531
.mat-form-field-ripple {
32+
$height: $mat-form-field-standard-underline-height * 2;
2633
bottom: 0;
27-
height: $mat-form-field-standard-underline-height * 2;
34+
height: $height;
35+
36+
@include cdk-high-contrast {
37+
height: 0;
38+
border-top: $height;
39+
}
2840
}
2941

3042
&.mat-form-field-disabled .mat-form-field-underline {

src/lib/form-field/form-field.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/vendor-prefixes';
3+
@import '../../cdk/a11y/a11y';
34

45

56
// Styles that apply to all appearances of the form-field.
@@ -52,6 +53,14 @@ $mat-form-field-default-infix-width: 180px !default;
5253
flex: auto;
5354
min-width: 0;
5455
width: $mat-form-field-default-infix-width;
56+
57+
// In high contrast mode IE/Edge will render all of the borders, even if they're transparent.
58+
// Since we can't remove the border altogether or replace it with a margin, because it'll throw
59+
// off the baseline, and we can't use a base64-encoded 1x1 transparent image because of CSP,
60+
// we work around it by setting a linear gradient that goes from `transparent` to `transparent`.
61+
@include cdk-high-contrast {
62+
border-image: linear-gradient(transparent, transparent);
63+
}
5564
}
5665

5766
// Used to hide the label overflow on IE, since IE doesn't take transform into account when

0 commit comments

Comments
 (0)