|
2 | 2 | outline: "deep" |
3 | 3 | --- |
4 | 4 |
|
5 | | -<script setup> |
6 | | - |
7 | | -const formIframeSrcDoc = ` |
8 | | -<!DOCTYPE html> |
9 | | -<html lang="en"> |
10 | | -<head> |
11 | | - <meta charset="UTF-8" /> |
12 | | - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
13 | | - <title>Accessible Form Example</title> |
14 | | -</head> |
15 | | -<body> |
16 | | - <h1>Form for Testing Accessibility</h1> |
17 | | - <main> |
18 | | - <form class="form js-form" id="f" action="#"> |
19 | | - <fieldset class="form__data"> |
20 | | - <legend>Subscribe now</legend> |
21 | | - <div class="form__name"> |
22 | | - <label |
23 | | - for="firstname" |
24 | | - data-validation="We need your first name to address you correctly" |
25 | | - > |
26 | | - <span class="form__field-name">First name</span> |
27 | | - <span aria-hidden="true" class="form__required">(required)</span> |
28 | | - </label> |
29 | | - <input |
30 | | - aria-describedby="firstname-validation" |
31 | | - required |
32 | | - id="firstname" |
33 | | - name="firstname" |
34 | | - type="text" |
35 | | - autocomplete="given-name" |
36 | | - /> |
37 | | - <small id="firstname-validation" class="form__validation"></small> |
38 | | - </div> |
39 | | - <div class="form__name"> |
40 | | - <label |
41 | | - for="lastname" |
42 | | - data-validation="We need your last name to address you correctly" |
43 | | - > |
44 | | - <span class="form__field-name">Last name</span> |
45 | | - <span aria-hidden="true" class="form__required">(required)</span> |
46 | | - </label> |
47 | | - <input |
48 | | - aria-describedby="lastname-validation" |
49 | | - required |
50 | | - id="lastname" |
51 | | - name="lastname" |
52 | | - type="text" |
53 | | - autocomplete="family-name" |
54 | | - /> |
55 | | - <small id="lastname-validation" class="form__validation"></small> |
56 | | - </div> |
57 | | - <div class="form__email"> |
58 | | - <label |
59 | | - for="email" |
60 | | - data-validation="We need your email address to be able to send you the newsletter" |
61 | | - > |
62 | | - <span class="form__field-name">Email address</span> |
63 | | - <span aria-hidden="true" class="form__required">(required)</span> |
64 | | - </label> |
65 | | - <input |
66 | | - aria-describedby="email-validation" |
67 | | - required |
68 | | - id="email" |
69 | | - name="email" |
70 | | - type="email" |
71 | | - autocomplete="email" |
72 | | - /> |
73 | | - <small id="email-validation" class="form__validation"></small> |
74 | | - </div> |
75 | | - </fieldset> |
76 | | -
|
77 | | - <button class="button button--red" type="submit">Subscribe</button> |
78 | | - </form> |
79 | | - </main> |
80 | | - <script>document.getElementById("f").addEventListener("submit", (e) => {e.preventDefault();console.log("submitted!");});<\/script> |
81 | | -</body> |
82 | | -</html> |
83 | | -` |
84 | | -</script> |
85 | | - |
86 | 5 | # WAI-ARIA |
87 | 6 |
|
88 | 7 | The [Web Accessibility Initiative - Accessible Rich Internet Applications](https://www.w3.org/WAI/intro/aria) (WAI-ARIA) document contains techniques for building fully accessible JavaScript widgets and web applications. It defines a set of attributes to help make web content and web applications more accessible to people with disabilities. |
@@ -216,4 +135,3 @@ Here's an example! |
216 | 135 |
|
217 | 136 | In this example, we have a table whose column headers have buttons that will sort the table. That sorting behavior is made evident for sighted users with some recognizable sort icon, but blind users wouldn't get any cues to the buttons' functionality. To compensate, we give the button a description using aria-describedby, pointing to a `<p>` tag outside of the table. We wouldn't want users to navigate to the `<p>` on its own, however, so we apply hidden to it. Now our sort button has a description of "Sort this table alphabetically by name." without any of the ensuing clutter! 🙌🏻 |
218 | 137 |
|
219 | | -<iframe :srcdoc="formIframeSrcDoc"></iframe> |
0 commit comments