Skip to content

Commit d86e2fe

Browse files
tombrunetWilcoFiersJym77
authored
6cfa84: Modify pass example 4 to be more realistic, using a dialog (#1819)
* Modify pass example 4 to use a dialog * Undo unnecessary changes * Update _rules/aria-hidden-no-focusable-content-6cfa84.md Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com> * Make close functional * Adding fail 7 in contrast to pass 4 * Clarify items in response to review comments * Expanded description * Tweak wording more * Update per review suggestions * Update aria-hidden-no-focusable-content-6cfa84.md Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com> Co-authored-by: Jean-Yves Moyen <jym@siteimprove.com>
1 parent f507822 commit d86e2fe

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

_rules/aria-hidden-no-focusable-content-6cfa84.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,28 @@ This `input` element is not part of the [sequential focus navigation][] because
9797

9898
#### Passed Example 4
9999

100-
This `a` element is part of the [sequential focus navigation][], but moves focus to the `input` element whenever it receives focus.
100+
This `a` element is not [focusable][] because it moves focus to the `input` element whenever it receives focus. These elements
101+
are sometimes referred to as 'focus sentinel' or 'bumper'. They are typically found before and after a modal / dialog in
102+
order to contain focus within the modal. Page authors do not want the sentinel to be visible, nor do they want them to be read by
103+
a screen reader. But, they do want the element to be part of the [sequential focus navigation][]. This allows the page author
104+
to detect that focus has left the dialog in order to wrap it to the top/bottom as appropriate.
101105

102106
```html
107+
<div id="sampleModal" role="dialog" aria-label="Sample Modal" aria-modal="true" style="border: solid black 1px; padding: 1rem;">
108+
<label>First and last name <input id="dialogFirst"></label><br />
109+
<button id="closeButton">Close button</button>
110+
</div>
103111
<div aria-hidden="true">
104-
<a href="/" style="position:absolute; top:-999em" onfocus="document.querySelector('input').focus()">First link</a>
112+
<a href="#" id="sentinelAfter" style="position:absolute; top:-999em">Upon receiving focus, this focus sentinel should wrap focus to the top of the modal</a>
105113
</div>
106-
<input />
114+
<script>
115+
document.getElementById("sentinelAfter").addEventListener("focus", () => {
116+
document.getElementById("dialogFirst").focus();
117+
});
118+
document.getElementById("closeButton").addEventListener("click", () => {
119+
document.getElementById("sampleModal").style.display = "none";
120+
});
121+
</script>
107122
```
108123

109124
#### Passed Example 5
@@ -169,6 +184,27 @@ This `summary` element is part of the [sequential focus navigation][].
169184
</details>
170185
```
171186

187+
#### Failed Example 6
188+
189+
This `a` element is [focusable][] because it fails to move focus when it receives focus. This is in contrast to a focus sentinel that
190+
immediately jumps focus to a valid location. Focus sentinels are typically used before and after a modal dialog in order to contain
191+
and wrap focus. In this case, the `focus` event was removed, but the sentinel was not.
192+
193+
```html
194+
<div id="sampleModal" role="dialog" aria-label="Sample Modal" aria-modal="true" style="border: solid black 1px; padding: 1rem;">
195+
<label>First and last name <input id="dialogFirst"></label><br />
196+
<button id="closeButton">Close button</button>
197+
</div>
198+
<div aria-hidden="true">
199+
<a href="#" id="sentinelAfter" style="position:absolute; top:-999em">Upon receiving focus, this focus sentinel should wrap focus to the top of the modal</a>
200+
</div>
201+
<script>
202+
document.getElementById("closeButton").addEventListener("click", () => {
203+
document.getElementById("sampleModal").style.display = "none";
204+
});
205+
</script>
206+
```
207+
172208
### Inapplicable
173209

174210
#### Inapplicable Example 1

0 commit comments

Comments
 (0)