Skip to content

Commit 0156893

Browse files
authored
Merge pull request #217 from wpaccessibility/157-group-form-fields
2 parents c975f59 + 0ec96ac commit 0156893

File tree

13 files changed

+259
-85
lines changed

13 files changed

+259
-85
lines changed
17.8 KB
Loading

docs/start/wcag-intro/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ There are 3 levels of accessibility:
7676

7777
TODO: add content about version
7878

79-
TODO: add info about different principle/ guideline/succes criteria/technique.
79+
TODO: add info about different principle/ guideline/Success Criteria/technique.
8080

8181
Most European Union and many other countries use the accessibility standard WCAG 2.1 AA or equivalent for their government websites. Some countries require compliance with these guidelines for commercial websites, so the accessibility team uses these guidelines to improve WordPress core. [Overview of government accessibility laws and policies](Web Accessibility Laws & Policies) from the Web Accessibility Initiative.
8282

docs/topics/code/accessible-name/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The accessibility tree of Firefox shows the following relevant information: The
8181
![Screenshot accessible name link in FireFox]({{site.baseurl}}/assets/images/accessible-name-link.png)
8282

8383

84-
## WCAG Succes Criteria
84+
## WCAG Success Criteria
8585

8686
Giving interactive elements a well-defined, accessible name is necessary to meet the WCAG success criteria:
8787

docs/topics/forms/descriptions/connect-description.md

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,74 +44,42 @@ It's possible to add multiple descriptions to one form field. You can combine th
4444
autocomplete="name" />
4545
```
4646

47-
## Connect the description of a fieldset to the fieldset element
48-
49-
Radio buttons, checkboxes, and other groups of related fields (like addresses) can be grouped in fieldsets. The question or the subject will be the `legend`. Place the description below the legend just above the first label/form field. The description is linked to the fieldset element with `aria-describedby`.
50-
51-
## Example
52-
53-
![Screenshot of a fieldset, with a legend and 2 radio buttons]({{site.baseurl}}/assets/images/fieldset-description.png)
54-
55-
IN HTML, simplified
56-
57-
```html
58-
<fieldset aria-describedby="description-log-in">
59-
<legend>Do you want to log in?</legend>
60-
<p id="description-log-in">
61-
When you log in, your details are already filled in, and we can help you faster.
62-
</p>
63-
<input
64-
id="log-in-yes"
65-
type="radio"
66-
name="log-in"
67-
value="yes"
68-
/>
69-
<label for="og-in-yes">Yes</label>
70-
71-
<input
72-
id="log-in-no"
73-
type="radio"
74-
name="log-in"
75-
value="no"
76-
/>
77-
<label for="log-in-no">No</label>
78-
79-
</fieldset>
80-
```
47+
{: .info }
48+
For the documentation about descriptions in fieldsets read [Description with a fieldset]({{site.baseurl}}/docs/topics/forms/fieldsets/fieldset-descriptions/).
8149

8250
## Examples
8351

84-
{: .do }
85-
Connect a description to the form field, using aria-describedby.
52+
{: .dont }
53+
No connection between a form field and its description.
8654

8755
```html
56+
<!-- do not copy, this is incorrect -->
8857
<label for="new-password">New password</label>
89-
<p id="description-new-password">
58+
<p>
9059
Choose a password of at least 8 characters long.
9160
</p>
9261
<input
9362
id="new-password"
9463
type="password"
9564
name="new-password"
96-
aria-describedby="description-new-password"
9765
autocomplete="new-password"
9866
/>
9967
```
10068

101-
{: .dont }
102-
No connection between a form field and its description.
69+
{: .do }
70+
Connection between a form field and its description.
10371

10472
```html
105-
<!-- do not copy, this is incorrect -->
10673
<label for="new-password">New password</label>
107-
<p>
74+
<p id="new-password-description">
10875
Choose a password of at least 8 characters long.
10976
</p>
11077
<input
11178
id="new-password"
11279
type="password"
11380
name="new-password"
11481
autocomplete="new-password"
82+
aria-describedby="new-password-description"
11583
/>
11684
```
11785

docs/topics/forms/descriptions/content-description.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ In this [demo video](https://www.youtube.com/watch?v=6brKmJfDtNQ), VoiceOver in
2020

2121
What are the options for adding information and explanations to a form and its input fields? Follow the [description decision tree]({{site.baseurl}}/docs/topics/forms/descriptions/).
2222

23-
## Related WCAG Success Criteria
23+
24+
## WCAG Success Criteria
2425

2526
- [1.3.1 Info and Relationships](https://www.w3.org/WAI/WCAG22/quickref/#info-and-relationships).
2627
- [3.3.2 Labels or Instructions](https://www.w3.org/WAI/WCAG22/quickref/#labels-or-instructions).
2728

29+
2830
## Resources
2931

3032
- NL Design System [Guidelines for web forms (Dutch content)](https://nldesignsystem.nl/richtlijnen/formulieren/).

docs/topics/forms/descriptions/decision-tree-description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Rich text in this context means: additional structure or interactive functionali
4444
**Yes**: Consider a multistep form, where the information is placed directly above the form for each step.
4545
**No**: Rewrite the description so that it only contains plain text. This ensures that all users can read the information.
4646

47-
## Related WCAG Success Criteria
47+
## WCAG Success Criteria
4848

4949
- [1.3.1 Info and Relationships](https://www.w3.org/WAI/WCAG22/quickref/#info-and-relationships).
5050
- [3.3.2 Labels or Instructions](https://www.w3.org/WAI/WCAG22/quickref/#labels-or-instructions).

docs/topics/forms/fieldsets.md

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Fieldset description
3+
layout: default
4+
parent: Group form fields
5+
nav_order: 3
6+
description: Connect the description of a fieldset to the fieldset element
7+
---
8+
9+
# Description with a fieldset
10+
11+
Radio buttons, checkboxes, and other groups of related fields (like addresses) can be grouped in fieldsets. The question or the subject will be the `legend`. Place the description below the legend just above the first label/form field. The description is linked to the fieldset element with `aria-describedby`.
12+
13+
## Example
14+
15+
![Screenshot of a fieldset, with a legend and 2 radio buttons]({{site.baseurl}}/assets/images/fieldset-description.png)
16+
17+
In HTML, simplified
18+
19+
```html
20+
<fieldset aria-describedby="description-log-in">
21+
<legend>Do you want to log in?</legend>
22+
<p id="description-log-in">
23+
When you log in, your details are already filled in, and we can help you faster.
24+
</p>
25+
<input
26+
id="log-in-yes"
27+
type="radio"
28+
name="log-in"
29+
value="yes"
30+
/>
31+
<label for="log-in-yes">Yes</label>
32+
33+
<input
34+
id="log-in-no"
35+
type="radio"
36+
name="log-in"
37+
value="no"
38+
/>
39+
<label for="log-in-no">No</label>
40+
41+
</fieldset>
42+
```
43+
44+
## Examples
45+
46+
{: .do }
47+
Connect a description to the form field, using aria-describedby.
48+
49+
```html
50+
<label for="new-password">New password</label>
51+
<p id="description-new-password">
52+
Choose a password of at least 8 characters long.
53+
</p>
54+
<input
55+
id="new-password"
56+
type="password"
57+
name="new-password"
58+
aria-describedby="description-new-password"
59+
autocomplete="new-password"
60+
/>
61+
```
62+
63+
## WCAG Success Criteria for descriptions
64+
65+
A description is optional, but it can help users to understand better what they need to fill out.
66+
Then a description with a fieldset is necessary to meet the WCAG success criterion [3.3.2 Labels or Instructions](https://www.w3.org/WAI/WCAG22/quickref/#labels-or-instructions) (Level AA).
67+
68+
## Related pages in this documentation
69+
70+
- [Group form fields]({{site.baseurl}}docs/topics/forms/fieldsets/).
71+
- [Fieldset legend]({{site.baseurl}}/docs/topics/forms/fieldsets/legend/).
72+
73+
## Resources
74+
75+
- MDN: [ARIA: aria-describedby attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-describedby).
76+
- NL Design System [Guidelines for web forms (Dutch content)](https://nldesignsystem.nl/richtlijnen/formulieren/).
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Group form fields
3+
layout: default
4+
parent: Web forms
5+
nav_order: 5
6+
description: Use fieldset and legend to group form fields.
7+
---
8+
9+
# Fieldset and legend to group form fields
10+
11+
Group form fields that belong together inside a `<fieldset>` with a descriptive `<legend>`. The advantage to this is that the form fields are grouped together both visually and semantically, making the design match the code.
12+
13+
The `fieldset` and `legend` elements are the native HTML way to group fields. When a screen reader enters a fieldset, the `legend` of that group will be announced. This is a helpful way of grouping related fields together, such as differentiating between an order address and a shipping address; but is critical when grouping radio buttons and checkboxes.
14+
15+
16+
<img src="{{site.baseurl}}/assets/images/fieldset-radio-buttons.png" alt="Screenshot of grouped radio buttons that let you select the best color">
17+
18+
19+
```html
20+
<fieldset>
21+
22+
<legend>Which is the best color?</legend>
23+
24+
<input name="colorOption" type="radio" id="purple" value="purple" />
25+
<label for="purple">Purple</label>
26+
27+
<input name="colorOption" type="radio" id="aubergine" value="aubergine" />
28+
<label for="aubergine">Aubergine</label>
29+
30+
<input name="colorOption" type="radio" id="magenta" value="magenta" />
31+
<label for="magenta">Magenta</label>
32+
33+
<input name="colorOption" type="radio" id="all" value="all" />
34+
<label for="all">All of the above</label>
35+
36+
</fieldset>
37+
```
38+
39+
WCAG requires that the structure and relationships are programmatically determinable, and fieldset/legend is one way to meet that. The same can be achieved by using `role="group"` and `aria-labelledby`. But always keep the [first rule of ARIA use](https://www.w3.org/TR/using-aria/#rule1) in mind:
40+
41+
> If you can use a native HTML element or attribute with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so.
42+
43+
## Example using ARIA (not preferred)
44+
45+
```html
46+
<div role="group" aria-labelledby="dummy-legend">
47+
48+
<h2 id="dummy-legend">Which is the best color?</h2>
49+
50+
<input name="colorOption" type="radio" id="purple" value="purple" />
51+
<label for="purple">Purple</label>
52+
53+
<input name="colorOption" type="radio" id="aubergine" value="aubergine" />
54+
<label for="aubergine">Aubergine</label>
55+
56+
<input name="colorOption" type="radio" id="magenta" value="magenta" />
57+
<label for="magenta">Magenta</label>
58+
59+
<input name="colorOption" type="radio" id="all" value="all" />
60+
<label for="all">All of the above</label>
61+
62+
</div>
63+
```
64+
65+
## WCAG Success Criteria for naming grouped form fields
66+
67+
Naming grouped form fields is necessary to meet the WCAG success criteria:
68+
69+
- [1.3.1 Info and relationships](https://www.w3.org/WAI/WCAG22/quickref/#info-and-relationships) (Level A).
70+
- [3.3.2 Labels or Instructions](https://www.w3.org/WAI/WCAG22/quickref/#labels-or-instructions) (Level AA).
71+
72+
## Resources
73+
74+
- W3C: [Grouping Controls](https://www.w3.org/WAI/tutorials/forms/grouping/)
75+
- NL Design System: [Guidelines for web forms (Dutch content)](https://nldesignsystem.nl/richtlijnen/formulieren/).
76+
- MDN: [The Field Set element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/fieldset).

0 commit comments

Comments
 (0)