Skip to content

Commit 0b0c1d8

Browse files
nilloqlouismaximepitonvprothaisMaxLardenois
authored
docs: input accessibility documentation improvements (#3268)
Co-authored-by: Louis-Maxime Piton <[email protected]> Co-authored-by: Vincent Prothais <[email protected]> Co-authored-by: Maxime Lardenois <[email protected]>
1 parent 14c0455 commit 0b0c1d8

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

site/src/content/docs/forms/select-input.mdx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ If the helper text is not sufficient, it’s possible to offer the user an addit
165165
To display a helper link below selects, use a standard small link [with `.link` and `.link-small` classes]([[docsref:/components/links#sizes]]) as a sibling of a `.select-input-container`.
166166

167167
<Callout type="warning">
168-
If a helper link is used in conjunction with a helper text, the `aria-describedby` attribute should refer to the helper text and the helper link should be referenced by the `aria-labelledby` attribute.
168+
Helper link should be explicitly labelled using the `aria-labelledby` attribute in which you must combine the helper link id and the related select input label id. This will ensure that assistive technologies—such as screen readers—will announce this helper link in relation with the select input. We also recommend adding a `.visually-hidden` span inside the link to coordinate the link content and the label.
169169
</Callout>
170170

171171
<Example buttonLabel="selects with helper link" code={`<div class="select-input mb-medium">
172172
<div class="select-input-container">
173173
<label id="labelSelectWithHelperAndLink" for="exampleSelectWithHelperAndLink">Select example with helper and link texts</label>
174-
<select class="select-input-field" id="exampleSelectWithHelperAndLink" aria-describedby="selectTextHelpBlock" aria-labelledby="labelSelectWithHelperAndLink selectTextLinkBlock">
174+
<select class="select-input-field" id="exampleSelectWithHelperAndLink" aria-describedby="selectTextHelpBlock">
175175
<option value="" disabled selected></option>
176176
<option value="1">One</option>
177177
<option value="2">Two</option>
@@ -181,22 +181,22 @@ If a helper link is used in conjunction with a helper text, the `aria-describedb
181181
<p id="selectTextHelpBlock" class="helper-text">
182182
Choose a number.
183183
</p>
184-
<a href="#" id="selectTextLinkBlock" class="link link-small">
185-
More information <span class="visually-hidden">about how to choose a number</span>
184+
<a href="#" id="selectTextLinkBlock" aria-labelledby="selectTextLinkBlock labelSelectWithHelperAndLink" class="link link-small">
185+
More information <span class="visually-hidden">about the</span>
186186
</a>
187187
</div>
188188
<div class="select-input">
189189
<div class="select-input-container">
190190
<label id="labelSelectWithLink" for="exampleSelectWithLink">Select example with link text</label>
191-
<select class="select-input-field" id="exampleSelectWithLink" aria-labelledby="labelSelectWithLink selectTextLink">
191+
<select class="select-input-field" id="exampleSelectWithLink">
192192
<option value="" disabled selected></option>
193193
<option value="1">One</option>
194194
<option value="2">Two</option>
195195
<option value="3">Three</option>
196196
</select>
197197
</div>
198-
<a href="#" id="selectTextLink" class="link link-small">
199-
More information <span class="visually-hidden">about how to choose a number with a link</span>
198+
<a href="#" id="selectTextLink" aria-labelledby="selectTextLink labelSelectWithLink" class="link link-small">
199+
More information <span class="visually-hidden">about the</span>
200200
</a>
201201
</div>`} />
202202

@@ -286,13 +286,13 @@ Add the `readonly` boolean attribute on an input to prevent modification of the
286286
To display an invalid select, add `.is-invalid` to a `.select-input-field` within the `.select-input-container`. Please take a look at our [Validation page to learn more]([[docsref:/forms/validation]]).
287287

288288
<Callout type="warning">
289-
For accessibility purposes, the invalid state should be associated with a `.error-text` as a sibling of a `.select-input-container` and related to it with an `aria-labelledby` attribute when displayed. Note that the `.error-text` will replace the helper text, so it should be descriptive enough to convey the error.
289+
For accessibility purposes, the invalid state should be associated with a `.error-text` as a sibling of a `.select-input-container` and related to it with an `aria-describedby` attribute when displayed. Note that the `.error-text` will replace the helper text, so it should be descriptive enough to convey the error note that the `.error-text` will replace the helper text, so it should be descriptive enough to convey the error and you must dynamically replace the `aria-describedby` attribute when the select input becomes invalid.
290290
</Callout>
291291

292292
<Example buttonLabel="invalid selects" code={`<div class="select-input mb-medium">
293293
<div class="select-input-container">
294294
<label id="labelErrorSelect" for="exampleErrorSelect">Select example with error</label>
295-
<select class="select-input-field is-invalid" id="exampleErrorSelect" aria-describedby="numberHelpText" aria-labelledby="labelErrorSelect numberFeedback numberLink">
295+
<select class="select-input-field is-invalid" id="exampleErrorSelect" aria-describedby="numberFeedback">
296296
<option value="" disabled selected></option>
297297
<option value="1">One</option>
298298
<option value="2">Two</option>
@@ -305,15 +305,15 @@ For accessibility purposes, the invalid state should be associated with a `.erro
305305
<p id="numberFeedback" class="error-text">
306306
A number is required.
307307
</p>
308-
<a href="#" id="numberLink" class="link link-small">
309-
More information <span class="visually-hidden">about how to choose a number from these three</span>
308+
<a href="#" id="numberLink" aria-labelledby="numberLink labelErrorSelect" class="link link-small">
309+
More information <span class="visually-hidden">about the</span>
310310
</a>
311311
</div>
312312
<div class="was-validated">
313313
<div class="select-input mb-medium">
314314
<div class="select-input-container">
315315
<label id="labelErrorValidatedSelect" for="exampleErrorValidatedSelect">Select example with validated error</label>
316-
<select class="select-input-field is-invalid" id="exampleErrorValidatedSelect" aria-describedby="validatedNumberHelpText" aria-labelledby="labelErrorValidatedSelect validatedNumberFeedback validatedNumberLink">
316+
<select class="select-input-field is-invalid" id="exampleErrorValidatedSelect" aria-describedby="validatedNumberFeedback">
317317
<option value="" disabled selected></option>
318318
<option value="1">One</option>
319319
<option value="2">Two</option>
@@ -326,15 +326,15 @@ For accessibility purposes, the invalid state should be associated with a `.erro
326326
<p id="validatedNumberFeedback" class="error-text">
327327
A number is required.
328328
</p>
329-
<a href="#" id="validatedNumberLink" class="link link-small">
330-
More information <span class="visually-hidden">about how to choose a number from the three available options</span>
329+
<a href="#" id="validatedNumberLink" aria-labelledby="validatedNumberLink labelErrorValidatedSelect" class="link link-small">
330+
More information <span class="visually-hidden">about the</span>
331331
</a>
332332
</div>
333333
</div>
334334
<div class="select-input mb-medium">
335335
<div class="select-input-container select-input-container-outlined">
336336
<label id="labelErrorSelect2" for="exampleErrorSelect2">Outlined select example with error</label>
337-
<select class="select-input-field is-invalid" id="exampleErrorSelect2" aria-describedby="numberHelpText2" aria-labelledby="labelErrorSelect2 numberFeedback2">
337+
<select class="select-input-field is-invalid" id="exampleErrorSelect2" aria-describedby="numberFeedback2">
338338
<option value="" disabled selected></option>
339339
<option value="1">One</option>
340340
<option value="2">Two</option>
@@ -354,7 +354,7 @@ For accessibility purposes, the invalid state should be associated with a `.erro
354354
<use xlink:href="${getVersionedDocsPath('/assets/img/ouds-web-sprite.svg#heart-empty')}"/>
355355
</svg>
356356
<label id="labelErrorSelect3" for="exampleErrorSelect3">Select example with error and icon</label>
357-
<select class="select-input-field is-invalid" id="exampleErrorSelect3" aria-describedby="numberHelpText3" aria-labelledby="labelErrorSelect3 numberFeedback3">
357+
<select class="select-input-field is-invalid" id="exampleErrorSelect3" aria-describedby="numberFeedback3">
358358
<option value="" disabled selected></option>
359359
<option value="1">One</option>
360360
<option value="2">Two</option>

site/src/content/docs/forms/text-area.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,28 @@ If the helper text is not sufficient, it’s possible to offer the user an addit
9191
To display a helper link below text areas, use a standard small link [with `.link` and `.link-small` classes]([[docsref:/components/links#sizes]]) as a sibling of a `.text-area-container`.
9292

9393
<Callout type="warning">
94-
If a helper link is used in conjunction with a helper text, the `aria-describedby` attribute should refer to the helper text and the helper link should be referenced by the `aria-labelledby` attribute.
94+
Helper link should be explicitly described using the `aria-labelledby` attribute in which you must combine the helper link id and the related text area label id. This will ensure that assistive technologies—such as screen readers—will announce this helper link in relation with the text area. We also recommend adding a `.visually-hidden` span inside the link to coordinate the link content and the label.
9595
</Callout>
9696

9797
<Example code={`<div class="text-area mb-medium">
9898
<div class="text-area-container">
9999
<label id="labelTextAreaWithHelperTextLink" for="textAreaWithHelperTextLink">Additional comments</label>
100-
<textarea id="textAreaWithHelperTextLink" aria-describedby="feedbackTextHelpBlock" aria-labelledby="labelTextAreaWithHelperTextLink feedbackTextHelpMore" class="text-area-field"></textarea>
100+
<textarea id="textAreaWithHelperTextLink" aria-describedby="feedbackTextHelpBlock" class="text-area-field"></textarea>
101101
</div>
102102
<p id="feedbackTextHelpBlock" class="helper-text">
103103
Please be concise and limit your comment to <strong>180</strong> characters.
104104
</p>
105-
<a href="#" id="feedbackTextHelpMore" class="link link-small">
106-
More information
105+
<a href="#" id="feedbackTextHelpMore" aria-labelledby="feedbackTextHelpMore labelTextAreaWithHelperTextLink" class="link link-small">
106+
More information <span class="visually-hidden">on</span>
107107
</a>
108108
</div>
109109
<div class="text-area">
110110
<div class="text-area-container mt-large">
111-
<label for="textAreaHelperLink">Additional comments</label>
112-
<textarea id="textAreaHelperLink" aria-describedby="feedbackTextHelpLink" class="text-area-field"></textarea>
111+
<label id="labelTextAreaHelperLink" for="textAreaHelperLink">Additional comments</label>
112+
<textarea id="textAreaHelperLink" class="text-area-field"></textarea>
113113
</div>
114-
<a href="#" id="feedbackTextHelpLink" class="link link-small">
115-
More information
114+
<a href="#" id="feedbackTextHelpMoreLink" aria-labelledby="feedbackTextHelpMoreLink labelTextAreaHelperLink" class="link link-small">
115+
More information <span class="visually-hidden">on</span>
116116
</a>
117117
</div>`} />
118118

@@ -175,13 +175,13 @@ Add the `readonly` boolean attribute on a text area to prevent modification of t
175175
To display an invalid text area, add `.is-invalid` to a `.text-area-field` within the `.text-area-container`. Please take a look at our [Validation page to learn more]([[docsref:/forms/validation]]).
176176

177177
<Callout type="warning">
178-
For accessibility purposes, the invalid state should be associated with a `.error-text` as a sibling of a `.text-area-container` and related to it with an `aria-labelledby` attribute when displayed. Note that the `.error-text` will replace the helper text, so it should be descriptive enough to convey the error.
178+
For accessibility purposes, the invalid state should be associated with a `.error-text` as a sibling of a `.text-area-container` and related to it with an `aria-describedby` attribute when displayed. Note that the `.error-text` will replace the helper text, so it should be descriptive enough to convey the error and you must dynamically replace the `aria-describedby` attribute when the text area becomes invalid.
179179
</Callout>
180180

181181
<Example code={`<div class="text-area mb-medium">
182182
<div class="text-area-container">
183183
<label id="labelTextAreaInvalid" for="exampleTextAreaInvalid">Additional comments</label>
184-
<textarea class="text-area-field is-invalid" id="exampleTextAreaInvalid" aria-describedby="commentTextHelpBlock" aria-labelledby="labelTextAreaInvalid commentFeedback"></textarea>
184+
<textarea class="text-area-field is-invalid" id="exampleTextAreaInvalid" aria-describedby="commentFeedback"></textarea>
185185
</div>
186186
<p id="commentTextHelpBlock" class="helper-text">
187187
Please be concise and limit your comment to <strong>180</strong> characters.
@@ -192,16 +192,16 @@ For accessibility purposes, the invalid state should be associated with a `.erro
192192
</div>
193193
<div class="text-area">
194194
<div class="text-area-container text-area-container-outlined">
195-
<label for="exampleTextAreaOutlinedInvalid">Additional comments</label>
196-
<textarea class="text-area-field is-invalid" id="exampleTextAreaOutlinedInvalid">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer viverra nisi turpis, vel dignissim enim imperdiet eu. Ut quis mollis erat. Pellentesque id leo pellentesque urna volutpat placerat non nec sem. Integer mauris eros, congue nec magna sit amet, pulvinar laoreet diam. Nam tristique nisl ac nisi aliquet, et molestie turpis maximus.</textarea>
195+
<label for="labelTextAreaOutlinedInvalid">Additional comments</label>
196+
<textarea class="text-area-field is-invalid" id="labelTextAreaOutlinedInvalid" aria-describedby="commentFeedbackOutlined">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer viverra nisi turpis, vel dignissim enim imperdiet eu. Ut quis mollis erat. Pellentesque id leo pellentesque urna volutpat placerat non nec sem. Integer mauris eros, congue nec magna sit amet, pulvinar laoreet diam. Nam tristique nisl ac nisi aliquet, et molestie turpis maximus.</textarea>
197197
</div>
198198
<p id="commentTextHelpBlockOutlined" class="helper-text">
199199
Please be concise and limit your comment to <strong>180</strong> characters.
200200
</p>
201201
<p id="commentFeedbackOutlined" class="error-text">
202202
Your comment exceeded the limit of <strong>180</strong> characters.
203203
</p>
204-
<a href="#" id="commentTextHelpLinkOutlined" class="link link-small">
205-
More information
204+
<a href="#" id="commentTextHelpLinkOutlined" aria-labelledby="commentTextHelpLinkOutlined labelTextAreaOutlinedInvalid" class="link link-small">
205+
More information <span class="visually-hidden">on</span>
206206
</a>
207207
</div>`} />

0 commit comments

Comments
 (0)