Skip to content

Commit 7bb9efc

Browse files
committed
Add .show-for-sr and .show-on-focus classes and update docs, closes #6366
1 parent 830c644 commit 7bb9efc

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="row">
2+
<div class="large-6 columns">
3+
<h4>HTML</h4>
4+
{{#markdown}}
5+
```html
6+
<p aria-hidden="true">This text can be seen, but won't be read by a screen reader.</p>
7+
```
8+
{{/markdown}}
9+
</div>
10+
<div class="large-6 columns">
11+
<h4>Rendered HTML</h4>
12+
<p aria-hidden="true">This text can be seen, but won't be read by a screen reader.</p>
13+
</div>
14+
</div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="row">
2+
<div class="large-6 columns">
3+
<h4>HTML</h4>
4+
{{#markdown}}
5+
```html
6+
<p class="show-for-sr">This text can only be read by a screen reader.</p>
7+
<p>There's a line of text above this one, you just can't see it.</p>
8+
```
9+
{{/markdown}}
10+
</div>
11+
<div class="large-6 columns">
12+
<h4>Rendered HTML</h4>
13+
<p class="show-for-sr">This text can only be read by a screen reader.</p>
14+
<p>There's a line of text above this one, you just can't see it.</p>
15+
</div>
16+
</div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="row">
2+
<div class="large-6 columns">
3+
<h4>HTML</h4>
4+
{{#markdown}}
5+
```html
6+
<p><a class="show-on-focus" href="#mainContent">Skip to Content</a></p>
7+
<div id="mainContent"></div>
8+
```
9+
{{/markdown}}
10+
</div>
11+
<div class="large-6 columns">
12+
<h4>Rendered HTML</h4>
13+
<p><a class="show-on-focus" href="#">Skip to Content</a></p>
14+
</div>
15+
</div>

doc/pages/components/visibility.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ <h3 class="subheader">Visibility classes let you show or hide elements based on
3939

4040
## Accessibility
4141

42+
Adding `display: none` to an element will prevent screen readers from reading it. However, there are techniques to hide content while still making it readable by screen readers.
43+
44+
### Show for Screen Readers Only
45+
46+
To visually hide content, while still allowing assistive technology to read it, add the class `show-for-sr`.
47+
48+
{{> examples_accessibility_showforsr}}
49+
50+
### Hide for Screen Readers Only
51+
52+
To hide text from assistive technology, while still keeping it visible, add the attribute `aria-hidden="true"`. This doesn't affect how the element looks, but screen readers will skip over it.
53+
54+
{{> examples_accessibility_hideforsr}}
55+
56+
### Creating Skip Links
57+
58+
If your site has a lot of navigation, a screen reader will have to read through the entire navigation to get to your site's content. To remedy this, you can add a "skip link" at the very top of your page, which will send the user farther down the page, past the navigation when clicked on.
59+
60+
Use the class `show-on-focus` to hide an element, *except* when it has focus.
61+
62+
{{> examples_accessibility_skiplinks}}
63+
64+
### Responsive Visibility
65+
4266
Finally, if you want to hide some content but still make it accessible for screen readers, use the **hidden** visibility classes. Do not confuse these classes with **hide** visibility classes. Use these classes in conjunction with the **hide** and **show** visibility classes to control complex layouts while offering accessibility for those using screen readers.
4367

4468
{{> examples_accessibility_hidden}}

scss/foundation/components/_visibility.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@ $visibility-breakpoint-queries:
390390
th.hide-for-touch { display: table-cell !important; }
391391
.touch th.show-for-touch { display: table-cell !important; }
392392

393+
/* Screen reader-specific classes */
394+
.show-for-sr {
395+
@include element-invisible;
396+
}
397+
.show-on-focus {
398+
@include element-invisible;
399+
400+
&:focus,
401+
&:active {
402+
@include element-invisible-off;
403+
}
404+
}
405+
393406
// Only include these styles if you want them.
394407
@if $include-print-styles {
395408
/*

0 commit comments

Comments
 (0)