Skip to content

Commit df9d32f

Browse files
patrickhlaukemxdvlmbgower
authored
Update G211 prose and wrong working example (#4555)
* correct the figure numbering * remove the inline working example for simplified accessible name * reuse the existing (but unlinked) `example3.html` to provide the actual working example for simplified accessible name * clean up how code blocks are marked up/indented Closes #4554 Previews: * https://deploy-preview-4555--wcag2.netlify.app/techniques/general/g211 * https://deploy-preview-4555--wcag2.netlify.app/working-examples/label-in-name-general/example3 --------- Co-authored-by: Max Duval <[email protected]> Co-authored-by: Mike Gower <[email protected]>
1 parent 0ccdefd commit df9d32f

File tree

4 files changed

+41
-70
lines changed

4 files changed

+41
-70
lines changed

techniques/general/G211.html

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h2>Examples</h2>
3333
<section class="example">
3434
<h3>Anchor text provides both the link's label and its accessible name</h3>
3535
<p id="linksample">Using conventional HTML, the text between the <code class="language-html">a</code> element's tags provides both the link's visible text and the accessible name "Code of conduct":</p>
36-
<code class="language-html">&lt;p&gt;Go to our &lt;a href="url-to-page-about-code.html"&gt;Code of conduct&lt;/a&gt;&lt;/p&gt;</code>
36+
<pre><code class="language-html">&lt;p&gt;Go to our &lt;a href="url-to-page-about-code.html"&gt;Code of conduct&lt;/a&gt;&lt;/p&gt;</code></pre>
3737
<section>
3838
<h4>Non-working sample of anchor</h4>
3939
<p>Go to our <a href="#linksample">Code of conduct</a></p>
@@ -44,19 +44,18 @@ <h4>Non-working sample of anchor</h4>
4444
<h3>Text in <code class="language-html">label</code> element provides name for input via <code class="language-html">for</code> attribute</h3>
4545
<p>The text between the <code class="language-html">label</code> tags also serves as the checkbox input's accessible name "Notify me of delays" by using the <code class="language-html">for</code> attribute which references the <code class="language-html">id</code> of the <code class="language-html">input</code>.</p>
4646
<pre><code class="language-html">&lt;input type="checkbox" id="notification" name="notify" value="delays"&gt;
47-
&lt;label for="notification"&gt;Notify me of delays&lt;/label&gt;
48-
</code></pre>
47+
&lt;label for="notification"&gt;Notify me of delays&lt;/label&gt;</code></pre>
4948
<section>
5049
<h4>Working sample of input</h4>
5150
<input type="checkbox" id="notification" name="notify" value="delays">
52-
<label for="notification">Notify me of delays</label>
51+
<label for="notification">Notify me of delays</label>
5352
</section>
5453
</section>
5554
<section class="example">
5655
<h3>The button text provides the accessible name</h3>
5756

5857
<p>The text inside a <code class="language-html">button</code> element becomes both its visible label and its accessible name:</p>
59-
<code class="language-html">&lt;button&gt;Send&lt;/button&gt;</code>
58+
<pre><code class="language-html">&lt;button&gt;Send&lt;/button&gt;</code></pre>
6059
<section>
6160
<h4>Non-working sample of button</h4>
6261
<button type="button">Send</button>
@@ -70,17 +69,15 @@ <h3>Simple Radio Button Group</h3>
7069
<img src="img/call-me-radio-button-group.png" alt="Call me when balance exceeds $10,000, Yes No">
7170
<figcaption>Figure 1 "Call me when balance exceeds $10,000 radio group, with Yes and No choices</figcaption>
7271
</figure>
73-
<p>The label for each component should be restricted to "Yes" and "No". To meet <a href="../../Understanding/info-and-relationships"> 1.3.1 Information and Relationships</a> and <a href="../../Understanding/labels-or-instructions.html"> 3.3.2 Labels or Instructions</a>, the "Call me…" text can be coded to convey the relationship to ATs, in this example by using a <code>fieldset</code> and <code>legend</code>.</p>
72+
<p>The label for each component should be restricted to "Yes" and "No". To meet <a href="../../Understanding/info-and-relationships"> 1.3.1 Information and Relationships</a> and <a href="../../Understanding/labels-or-instructions.html"> 3.3.2 Labels or Instructions</a>, the "Call me…" text can be coded to convey the relationship to ATs, in this example by using a <code class="language-html">fieldset</code> and <code class="language-html">legend</code>.</p>
7473
<p>If the label is not restricted to the string adjacent to the radio button, multiple interpretations of what constitutes the label can result in less uniform functionality. If "Yes" alone is not the label for the first radio button, is it "Call me when balance exceeds $10,000"? Or is it a combination of text strings, in which case is the order "Call me when balance exceeds $10,000 Yes" or "Yes, Call me when balance exceeds $10,000"? Decisions to combine text strings can have negative effects on screen reader users since the order of concatenation can affect meaning. In this example, "No, call me when balance exceeds $10,000" could be very confusing to a screen reader user.</p>
75-
<code>
76-
&lt;fieldset&gt;<br>
77-
&lt;legend&gt;Call me when balance exceeds $10,000?&lt;/legend&gt;&lt;br /&gt;<br>
78-
&lt;input type="radio" id="yes" name="callme" value="yes"&gt;<br>
79-
&lt;label for="yes"&gt;Yes&lt;/label&gt;<br>
80-
&lt;input type="radio" id="no" name="callme" value="no"&gt;<br>
81-
&lt;label for="no"&gt;No&lt;/label&gt;<br>
82-
&lt;/fieldset&gt;<br>
83-
</code>
74+
<pre><code class="language-html">&lt;fieldset&gt;
75+
&lt;legend&gt;Call me when balance exceeds $10,000?&lt;/legend&gt;&lt;br /&gt;
76+
&lt;input type="radio" id="yes" name="callme" value="yes"&gt;
77+
&lt;label for="yes"&gt;Yes&lt;/label&gt;
78+
&lt;input type="radio" id="no" name="callme" value="no"&gt;
79+
&lt;label for="no"&gt;No&lt;/label&gt;
80+
&lt;/fieldset&gt;</code></pre>
8481
<p class="working-example"><a href="../../working-examples/label-in-name-general/example1.html">Working example of Simple Radio Button Group</a></p>
8582
</section>
8683
<section class="example">
@@ -109,20 +106,17 @@ <h3>Stacked Labels</h3>
109106
<p>Figure 4 shows a variation on stacked labels, where hints and guidance are included between the label and the input. This design does not provide an adjacent label. However, the "New Password" label is still considered to be in close enough proximity, especially given its size and boldness relative to the smaller and lower-contrast guidance text. The associations are reinforced programmatically, where the hint text is given a role of <code class="language-html">aria-describedby</code> and the label is properly associated with the input.</p>
110107
<figure id="figure-new-password">
111108
<img src="img/new-password.png" alt="New Password. Passwords must be 10 or more characters, and contain at least one capital, numeric and non-alphanumeric.'">
112-
<figcaption>Figure 4 New Password label positioned above input with a smaller-point text string about the password requirements positioned between the large label and the input.</figcaption>
109+
<figcaption>Figure 4 "New password" label positioned above input with a smaller-point text string about the password requirements positioned between the large label and the input.</figcaption>
113110
</figure>
114111
<p>The hint text in such implementations should be kept to a single line where possible, since accessibility issues can arise where a more lengthy hint separates the label from its input. Figure 4 illustrates that the concept of "adjacent text" is a guide for label interpretation, but cannot always serve as a hard rule.</p>
115-
<code>
116-
&lt;form&gt;<br>
117-
&lt;label class="label" for="example-2"&gt;<br>
118-
Password<br>
119-
&lt;/label&gt;<br>
120-
&lt;span id="example-2-hint" class="hint"&gt;<br>
121-
Passwords must be 10 or more characters, and contain at least one capital, numeric and non-alphanumeric.<br>
122-
&lt;/span&gt;<br>
123-
&lt;input class="input" id="example-2" name="example-2" type="text" aria-describedby="example-2-hint"&gt;<br>
124-
&lt;/form&gt;<br>
125-
</code>
112+
<pre><code class="language-html">&lt;form&gt;
113+
&lt;label class="label" for="example-2"&gt;New password&lt;/label&gt;
114+
&lt;span id="example-2-hint" class="hint"&gt;
115+
Passwords must be 10 or more characters, and contain at least one capital, numeric and non-alphanumeric.
116+
&lt;/span&gt;
117+
&lt;input class="input" id="example-2" name="example-2" type="password"
118+
autocomplete="new-password" aria-describedby="example-2-hint"&gt;
119+
&lt;/form&gt;</code></pre>
126120
<p class="working-example"><a href="../../working-examples/label-in-name-general/example2.html">Working example of stacked labels</a></p>
127121

128122
</section>
@@ -132,11 +126,11 @@ <h3>Range of inputs with few labels</h3>
132126
<p>A less common disparity between labels and inputs can occur when a group of radio buttons is set up to elicit a choice across a range. The labels may only be located at each end of the range or may be interspersed at various points in the range.</p>
133127
<figure id="figure-rate-response">
134128
<img src="img/rate-response.png" alt="Rate your response, Hated it, Loved it">
135-
<figcaption>Figure 6 Line of 5 radio buttons with Hated it and Loved it labels at each end</figcaption>
129+
<figcaption>Figure 5 Line of 5 radio buttons with Hated it and Loved it labels at each end</figcaption>
136130
</figure>
137131

138132
<p>The two labels, "Hated it" and "Loved it", are adjacent to the first and last radio buttons, and should be their accessible names. Speech-input users can speak either of these labels to select a radio button, and then use arrow navigation (e.g., "Press right arrow") to modify the selection. "Rate your response" is the text describing the whole widget and can be associated as the group label (here using <code class="language-html">legend</code>). The three middle radio buttons do not have visible labels. In the code example they are given title attributes of "Disliked", "So-so" and "Liked" in order to meet 3.3.2 Labels or Instructions.</p>
139-
<pre><code class="language-html">&lt;fieldset&gt;
133+
<pre><code class="language-html">&lt;fieldset&gt;
140134
&lt;legend&gt;Rate your response&lt;/legend&gt;
141135
&lt;label for="hated"&gt;Hated it&lt;/label&gt;
142136
&lt;input type="radio" name="meal" id="hated" value="hated"&gt;
@@ -145,46 +139,24 @@ <h3>Range of inputs with few labels</h3>
145139
&lt;input type="radio" name="meal" id="okay" value="okay" title="Liked"&gt;
146140
&lt;input type="radio" name="meal" id="loved" value="loved"&gt;
147141
&lt;label for="loved"&gt;Loved it&lt;/label&gt;
148-
&lt;/fieldset&gt;
149-
</code></pre>
142+
&lt;/fieldset&gt;</code></pre>
150143
<p class="working-example"><a href="../../working-examples/label-in-name-general/example4.html">Working example of range of inputs</a></p>
151144
</section>
152145

153146
<section class="example">
154147
<h3>Text in parentheses and punctuation</h3>
155148
<p>Technique G211 is not intended to complicate existing conventions for the construction of accessible form inputs. As described in the <em>Punctuation and capitalization</em> and <em>Text in parentheses</em> subsections of the Understanding document, information does not always need to be included in the accessible name in an attempt to meet the Label in Name requirement, especially where the text would not normally be spoken when using speech recognition to navigate to controls. Where there are established ways of ensuring information and relationships conveyed visually are present programmatically, it is acceptable to leave text in parentheses and punctuation out of the accessible name.</p>
156149
<p>The following snippet demonstrates possible techniques mentioned in the Understanding document. Since the required field is programmatically indicated, and the input restrictions on the date are surfaced through <code class="language-html">aria-describedby</code>, the asterisk and parenthetical information has been left out of the accessible name.</p>
150+
<figure id="figure-rate-response">
151+
<img src="img/inputs-simplified-accname.png" alt="Two text inputs: one with a label of 'Name' with an asterisk, one with a label of 'Birth date' and, in parentheses, YYYY-MM-DD">
152+
<figcaption>Figure 6 The "Name" and "Birth date" labels with additional information (and asterisk and an input formatting instruction, respectively)</figcaption>
153+
</figure>
154+
<pre><code class="language-html">&lt;label for="name"&gt;Name&lt;/label&gt; *
155+
&lt;input type="text" name="name" id="name" autocomplete="name" required&gt;
156+
&lt;label for="birth"&gt;Birth date&lt;/label&gt; (&lt;span id="mask"&gt;YYYY-MM-DD&lt;/span&gt;)
157+
&lt;input type="text" name="birth" id="birth" autocomplete="bday" aria-describedby="mask"&gt;</code></pre>
157158

158-
<pre><code class="language-html">
159-
&lt;label for="name"&gt;Name&lt;/label&gt; *
160-
&lt;input type="text" name="name" id="name" required&gt;
161-
&lt;label for="birth"&gt;Birth date&lt;/label&gt; &lt;span id="mask"&gt;(YYYY-MM-DD)&lt;/span&gt;
162-
&lt;input type="text" name="birth" id="birth" aria-describedby="mask"&gt;</code></pre>
163-
164-
<section>
165-
<h4>Working sample of inputs with simplified accessible names</h4>
166-
167-
168-
<div><label for="name">Name</label> *</div>
169-
<input type="text" name="name" id="name" required="required">
170-
<div><label for="birth">Birthdate</label> <span id="mask">(YYYY-MM-DD)</span></div>
171-
<input type="text" name="birth" id="birth" aria-describedby="mask">
172-
</section>
173-
174-
<p>
175-
<code>
176-
&lt;fieldset&gt;<br>&lt;legend&gt;Rate your response&lt;/legend&gt;<br>
177-
&lt;label for="hated"&gt;Hated it&lt;/label&gt; <br>
178-
&lt;input type="radio" name="meal" id="hated" value="hated"&gt;<br>
179-
&lt;input type="radio" name="meal" id="poor" value="poor" title="Disliked"&gt;<br>
180-
&lt;input type="radio" name="meal" id="neutral" value="neutral" title="So-so"&gt;<br>
181-
&lt;input type="radio" name="meal" id="okay" value="okay" title="Liked"&gt;<br>
182-
&lt;input type="radio" name="meal" id="loved" value="loved"&gt;<br>
183-
&lt;label for="loved"&gt;Loved it&lt;/label&gt;<br>
184-
&lt;/fieldset&gt;<br>
185-
</code>
186-
</p>
187-
<p class="working-example"><a href="../../working-examples/label-in-name-general/example4.html">Working example of range of inputs</a></p>
159+
<p class="working-example"><a href="../../working-examples/label-in-name-general/example3.html">Working example of inputs with simplified accessible names</a></p>
188160

189161
</section>
190162
</section>
1.4 KB
Loading

working-examples/label-in-name-general/example2.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454

5555
<div class="form-group">
5656
<label class="label" for="example-2">
57-
Password
57+
New password
5858
</label>
5959
<span id="example-2-hint" class="hint">
6060
Must be 10 or more characters, and contain at least one capital, numeric and non-alphanumeric.
6161
</span>
62-
<input class="input" id="example-2" name="example-2" type="text" aria-describedby="example-2-hint">
62+
<input class="input" id="example-2" name="example-2" type="password" autocomplete="new-password" aria-describedby="example-2-hint">
6363
</div>
6464
</form>
6565
</body>

working-examples/label-in-name-general/example3.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
66

7-
<title>Example of Work Phone input set</title>
7+
<title>Example of inputs with simplified accessible names</title>
88
<style>
99
html{
1010
background: white;
@@ -19,14 +19,13 @@
1919
letter-spacing: inherit;
2020
word-spacing: inherit;
2121
}
22+
input { display: block; }
2223
</style>
2324
</head>
2425
<body>
25-
<div role="group" aria-labelledby="groupLabel">
26-
<span id="groupLabel">Work Phone:</span>
27-
<input type="tel" aria-labelledby="groupLabel" title="area code">
28-
<input type="tel" title="prefix">
29-
<input type="tel" title="line number">
30-
</div>
26+
<label for="name">Name</label> *
27+
<input type="text" name="name" id="name" autocomplete="name" required>
28+
<label for="birth">Birth date</label> (<span id="mask">YYYY-MM-DD</span>)
29+
<input type="text" name="birth" id="birth" autocomplete="bday" aria-describedby="mask">
3130
</body>
3231
</html>

0 commit comments

Comments
 (0)