|
| 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 | +} |
0 commit comments