Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit b5de054

Browse files
Splaktarmmalerba
authored andcommitted
fix(input): floating label text fails a11y contrast audit (#11497)
add special handling for Firefox placeholders add `::placeholder` to the list of pseudos remove duplicate `::-webkit-input-placeholder` add `::-ms-input-placeholder` for Edge fix demo a11y issues Relates to #11475
1 parent 4acef53 commit b5de054

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/components/input/demoBasicUsage/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<md-input-container>
2828
<label>Enter date</label>
29-
<md-datepicker ng-model="user.submissionDate"></md-datepicker>
29+
<md-datepicker ng-model="user.submissionDate" aria-label="Enter date"></md-datepicker>
3030
</md-input-container>
3131
</div>
3232

@@ -48,7 +48,7 @@
4848
</md-input-container>
4949

5050
<md-input-container md-no-float class="md-block">
51-
<input ng-model="user.address2" placeholder="Address 2">
51+
<input ng-model="user.address2" placeholder="Address 2" aria-label="Address 2">
5252
</md-input-container>
5353

5454
<div layout-gt-sm="row">

src/components/input/demoErrorsAdvanced/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
transition: all 0.3s cubic-bezier(0.55, 0, 0.55, 0.2);
1212

1313
/* Set our own color */
14-
color: grey;
14+
color: rgba(0, 0, 0, 0.54);
1515
}
1616

1717
/* NOTE: Check the demo's HTML to see some additional RTL support CSS */

src/components/input/demoIcons/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111

1212
<md-input-container md-no-float class="md-block">
1313
<md-icon md-svg-src="img/icons/ic_phone_24px.svg"></md-icon>
14-
<input ng-model="user.phone" type="text" placeholder="Phone Number">
14+
<input ng-model="user.phone" type="text" placeholder="Phone Number" aria-label="Phone Number">
1515
</md-input-container>
1616

1717
<md-input-container class="md-block">
1818
<!-- Use floating placeholder instead of label -->
1919
<md-icon md-svg-src="img/icons/ic_email_24px.svg" class="email"></md-icon>
20-
<input ng-model="user.email" type="email" placeholder="Email (required)" ng-required="true">
20+
<input ng-model="user.email" type="email" placeholder="Email (required)" ng-required="true"
21+
aria-label="Email (required)">
2122
</md-input-container>
2223

2324
<md-input-container md-no-float class="md-block">
24-
<input ng-model="user.address" type="text" placeholder="Address" >
25+
<input ng-model="user.address" type="text" placeholder="Address" aria-label="Address">
2526
<md-icon md-svg-src="img/icons/ic_place_24px.svg" style="display:inline-block;"></md-icon>
2627
</md-input-container>
2728

src/components/input/input-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
md-input-container.md-THEME_NAME-theme {
22
.md-input {
3-
@include input-placeholder-color('\'{{foreground-3}}\'');
3+
@include input-placeholder-color('\'{{foreground-2}}\'');
44
color: '{{foreground-1}}';
55
border-color: '{{foreground-4}}';
66
}
@@ -11,7 +11,7 @@ md-input-container.md-THEME_NAME-theme {
1111

1212
label,
1313
.md-placeholder {
14-
color: '{{foreground-3}}';
14+
color: '{{foreground-2}}';
1515
}
1616

1717
label.md-required:after {

src/core/style/mixins.scss

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
}
1616

1717
@mixin input-placeholder-color($color) {
18-
$pseudos: '::-webkit-input-placeholder', ':-moz-placeholder', '::-moz-placeholder',
19-
':-ms-input-placeholder', '::-webkit-input-placeholder';
18+
$pseudos: '::-webkit-input-placeholder', // For QQ Browser
19+
':-ms-input-placeholder', // For IE
20+
'::-ms-input-placeholder', // For Edge
21+
'::placeholder';
22+
$firefox-pseudos: ':-moz-placeholder', '::-moz-placeholder';
2023

2124
// It is important to export every pseudo within its own block, because otherwise the placeholder
2225
// won't be set on the most browsers.
@@ -25,6 +28,14 @@
2528
color: unquote($color);
2629
}
2730
}
31+
// Firefox reduces the opacity of placeholders so we need to keep them opaque to avoid applying
32+
// double the transparency and causing a11y failures due to text contrast.
33+
@each $pseudo in $firefox-pseudos {
34+
&#{$pseudo} {
35+
color: unquote($color);
36+
opacity: 1;
37+
}
38+
}
2839
}
2940

3041
@mixin pie-clearfix {

0 commit comments

Comments
 (0)