Skip to content

Commit c47d0bf

Browse files
authored
Merge pull request #181 from BeAPI/fix/sr-only-css-class
styles : change visuallyhidden basic class to sr-only accessible class
2 parents ae20a78 + ba9a78d commit c47d0bf

File tree

7 files changed

+65
-15
lines changed

7 files changed

+65
-15
lines changed

src/scss/abstract/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@import "./m-radio-custom";
3232
@import "./m-row-fullwidth";
3333
@import "./m-select-custom";
34+
@import "./m-sr-only";
3435
@import "./m-style-only";
3536
@import "./m-title";
3637
@import "./m-word-wrap";

src/scss/abstract/_m-checkbox-custom.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
input[type="checkbox"],
99
input[type="radio"] {
1010

11-
@extend .visuallyhidden;
11+
@include sr-only;
1212

1313
+ label {
1414
position: relative;

src/scss/abstract/_m-sr-only.scss

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Improved screen reader only CSS class
3+
@see https://gist.github.com/ffoodd/000b59f431e3e64e4ce1a24d5bb36034
4+
@author Gaël Poupard
5+
@note Based on Yahoo!'s technique
6+
@author Thierry Koblentz
7+
@see https://developer.yahoo.com/blogs/ydn/clip-hidden-content-better-accessibility-53456.html
8+
* 1.
9+
@note `clip` is deprecated but works everywhere
10+
@see https://developer.mozilla.org/en-US/docs/Web/CSS/clip
11+
* 2.
12+
@note `clip-path` is the future-proof version, but not very well supported yet
13+
@see https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path
14+
@see http://caniuse.com/#search=clip-path
15+
@author Yvain Liechti
16+
@see https://twitter.com/ryuran78/status/778943389819604992
17+
* 3.
18+
@note preventing text to be condensed
19+
author J. Renée Beach
20+
@see https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe
21+
@note Drupal 8 goes with word-wrap: normal instead
22+
@see https://www.drupal.org/node/2045151
23+
@see http://cgit.drupalcode.org/drupal/commit/?id=5b847ea
24+
* 4.
25+
@note !important is important
26+
@note Obviously you wanna hide something
27+
@author Harry Roberts
28+
@see https://csswizardry.com/2016/05/the-importance-of-important/
29+
*/
30+
31+
@mixin sr-only($focusable: false) {
32+
width: 1px !important;
33+
height: 1px !important;
34+
padding: 0 !important;
35+
margin: -1px !important;
36+
overflow: hidden !important;
37+
clip: rect(1px, 1px, 1px, 1px) !important; /* 1 */
38+
clip-path: inset(50%) !important; /* 2 */
39+
white-space: nowrap !important; /* 3 */
40+
border: 0 !important;
41+
42+
@if $focusable {
43+
&:focus,
44+
&:active {
45+
width: auto !important;
46+
height: auto !important;
47+
margin: auto !important;
48+
overflow: visible !important;
49+
clip: auto !important;
50+
clip-path: none !important;
51+
white-space: normal !important;
52+
}
53+
}
54+
}
55+
56+
.sr-only {
57+
@include sr-only;
58+
}
59+
60+
.sr-only-focusable {
61+
@include sr-only(true);
62+
}

src/scss/base/_svg-icons.scss

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

1616
//display hidden text for icon only button
1717
.no-svg {
18-
.visuallyhidden {
18+
.sr-only {
1919
position: static;
2020
width: auto;
2121
height: auto;

src/scss/base/_visuallyhidden.scss

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/scss/editor.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ $entry-file-name: "editor";
88

99
@import "base/fonts";
1010
@import "base/box-sizing";
11-
@import "base/visuallyhidden";
1211
@import "base/text";
1312

1413
// Components

src/scss/style.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ $entry-file-name: "style";
1010

1111
@import "base/fonts";
1212
@import "base/box-sizing";
13-
@import "base/visuallyhidden";
1413
@import "base/svg-icons";
1514
@import "base/text";
1615
@import "base/form";

0 commit comments

Comments
 (0)