Skip to content

Commit 2bfd08c

Browse files
committed
[test][FormControlLabel] Add axe tests and WCAG conformance report
1 parent 5aa0b92 commit 2bfd08c

12 files changed

Lines changed: 729 additions & 3 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"FormControlLabelA11yStates": {
3+
"rules": {
4+
"aria-allowed-attr": {
5+
"status": "pass",
6+
"tags": ["wcag2a"]
7+
},
8+
"aria-conditional-attr": {
9+
"status": "pass",
10+
"tags": ["wcag2a"]
11+
},
12+
"aria-deprecated-role": {
13+
"status": "pass",
14+
"tags": ["wcag2a"]
15+
},
16+
"aria-hidden-focus": {
17+
"status": "pass",
18+
"tags": ["wcag2a"]
19+
},
20+
"aria-prohibited-attr": {
21+
"status": "pass",
22+
"tags": ["wcag2a"]
23+
},
24+
"aria-required-attr": {
25+
"status": "pass",
26+
"tags": ["wcag2a"]
27+
},
28+
"aria-roles": {
29+
"status": "pass",
30+
"tags": ["wcag2a"]
31+
},
32+
"aria-valid-attr": {
33+
"status": "pass",
34+
"tags": ["wcag2a"]
35+
},
36+
"aria-valid-attr-value": {
37+
"status": "pass",
38+
"tags": ["wcag2a"]
39+
},
40+
"color-contrast": {
41+
"status": "pass",
42+
"tags": ["wcag2aa"]
43+
},
44+
"form-field-multiple-labels": {
45+
"status": "pass",
46+
"tags": ["wcag2a"]
47+
},
48+
"label": {
49+
"status": "pass",
50+
"tags": ["wcag2a"]
51+
},
52+
"nested-interactive": {
53+
"status": "pass",
54+
"tags": ["wcag2a"]
55+
},
56+
"target-size": {
57+
"status": "pass",
58+
"tags": ["wcag22aa"]
59+
}
60+
}
61+
}
62+
}

‎docs/data/material/getting-started/accessibility/accessibility.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<p class="description">How Material UI components conform to WCAG 2.2 Level A and AA, reported in VPAT terms for procurement and accessibility review.</p>
44

55
:::warning
6-
**Draft — partial coverage.** This report covers the 13 components assessed so far, not the whole library. It has not been reviewed by an external auditor, and no assistive-technology testing has been performed yet. See [Scope and limitations](#scope-and-limitations) before relying on it for a procurement decision.
6+
**Draft — partial coverage.** This report covers the 14 components assessed so far, not the whole library. It has not been reviewed by an external auditor, and no assistive-technology testing has been performed yet. See [Scope and limitations](#scope-and-limitations) before relying on it for a procurement decision.
77
:::
88

99
## About this report
@@ -43,6 +43,7 @@ Each row counts only the criteria that **apply** to that component; criteria tha
4343
| [Button](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Button/accessibility.md) | 15 | 12 | 27 | 24 | 3 | 20/27 | 11 |
4444
| [Checkbox](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Checkbox/accessibility.md) | 14 | 11 | 25 | 24 | 1 | 22/25 | 11 |
4545
| [CircularProgress](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/CircularProgress/accessibility.md) | 6 | 5 | 11 | 8 | 3 | 6/11 | 1 |
46+
| [FormControlLabel](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/FormControlLabel/accessibility.md) | 8 | 7 | 15 | 15 | 0 | 14/15 | 5 |
4647
| [LinearProgress](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/LinearProgress/accessibility.md) | 6 | 5 | 11 | 8 | 3 | 6/11 | 1 |
4748
| [Radio](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Radio/accessibility.md) | 14 | 11 | 25 | 24 | 1 | 23/25 | 11 |
4849
| [RadioGroup](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/RadioGroup/accessibility.md) | 6 | 1 | 7 | 7 | 0 | 4/7 | 2 |
@@ -106,7 +107,7 @@ const theme = createTheme({ focusVisible: true });
106107
Read this section before citing the report.
107108
:::
108109

109-
- **Component coverage is partial.** 13 components are assessed. Widely used components including Select, Autocomplete, Dialog, Menu, Table, Tabs, Slider, Tooltip, Snackbar, and Drawer are **not yet assessed**, and this report says nothing about them.
110+
- **Component coverage is partial.** 14 components are assessed. Widely used components including Select, Autocomplete, Dialog, Menu, Table, Tabs, Slider, Tooltip, Snackbar, and Drawer are **not yet assessed**, and this report says nothing about them.
110111
- **No assistive-technology testing.** No screen-reader passes have been performed. Criteria that depend on how a specific assistive technology behaves are assessed from the exposed accessibility tree, not from observed behavior.
111112
- **Level AAA is out of scope**, as it is for a standard VPAT.
112113
- **Components are rated in isolation**, as rendered with default props and the default theme. Customization, composition, and your surrounding page can change the result.

‎docs/data/material/getting-started/accessibility/scorecard.json‎

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"standard": "WCAG 2.2 Level A and AA",
3-
"componentCount": 13,
3+
"componentCount": 14,
44
"totals": {
55
"rated": 32,
66
"supports": 27,
@@ -1538,6 +1538,165 @@
15381538
"automated": 1
15391539
}
15401540
},
1541+
{
1542+
"component": "FormControlLabel",
1543+
"counts": {
1544+
"supports": 15,
1545+
"partiallySupports": 0,
1546+
"doesNotSupport": 0,
1547+
"notApplicable": 40,
1548+
"flagged": 1,
1549+
"rated": 15
1550+
},
1551+
"gaps": [],
1552+
"criteria": [
1553+
{
1554+
"number": "1.1.1",
1555+
"name": "Non-text Content",
1556+
"level": "A",
1557+
"conformance": "Supports",
1558+
"responsibility": "Shared",
1559+
"group": "Hybrid",
1560+
"flagged": false
1561+
},
1562+
{
1563+
"number": "1.3.1",
1564+
"name": "Info and Relationships",
1565+
"level": "A",
1566+
"conformance": "Supports",
1567+
"responsibility": "Shared",
1568+
"group": "Hybrid",
1569+
"flagged": false
1570+
},
1571+
{
1572+
"number": "1.3.2",
1573+
"name": "Meaningful Sequence",
1574+
"level": "A",
1575+
"conformance": "Supports",
1576+
"responsibility": "Author",
1577+
"group": "Manual",
1578+
"flagged": false
1579+
},
1580+
{
1581+
"number": "1.3.3",
1582+
"name": "Sensory Characteristics",
1583+
"level": "A",
1584+
"conformance": "Supports",
1585+
"responsibility": "Author",
1586+
"group": "Manual",
1587+
"flagged": false
1588+
},
1589+
{
1590+
"number": "1.4.1",
1591+
"name": "Use of Color",
1592+
"level": "A",
1593+
"conformance": "Supports",
1594+
"responsibility": "Shared",
1595+
"group": "Hybrid",
1596+
"flagged": true
1597+
},
1598+
{
1599+
"number": "1.4.3",
1600+
"name": "Contrast (Minimum)",
1601+
"level": "AA",
1602+
"conformance": "Supports",
1603+
"responsibility": "Shared",
1604+
"group": "Hybrid",
1605+
"flagged": false
1606+
},
1607+
{
1608+
"number": "1.4.4",
1609+
"name": "Resize Text",
1610+
"level": "AA",
1611+
"conformance": "Supports",
1612+
"responsibility": "Shared",
1613+
"group": "Automated",
1614+
"flagged": false
1615+
},
1616+
{
1617+
"number": "1.4.5",
1618+
"name": "Images of Text",
1619+
"level": "AA",
1620+
"conformance": "Supports",
1621+
"responsibility": "Author",
1622+
"group": "Manual",
1623+
"flagged": false
1624+
},
1625+
{
1626+
"number": "1.4.10",
1627+
"name": "Reflow",
1628+
"level": "AA",
1629+
"conformance": "Supports",
1630+
"responsibility": "Shared",
1631+
"group": "Automated",
1632+
"flagged": false
1633+
},
1634+
{
1635+
"number": "1.4.12",
1636+
"name": "Text Spacing",
1637+
"level": "AA",
1638+
"conformance": "Supports",
1639+
"responsibility": "Shared",
1640+
"group": "Automated",
1641+
"flagged": false
1642+
},
1643+
{
1644+
"number": "2.4.6",
1645+
"name": "Headings and Labels",
1646+
"level": "AA",
1647+
"conformance": "Supports",
1648+
"responsibility": "Shared",
1649+
"group": "Hybrid",
1650+
"flagged": false
1651+
},
1652+
{
1653+
"number": "2.5.3",
1654+
"name": "Label in Name",
1655+
"level": "A",
1656+
"conformance": "Supports",
1657+
"responsibility": "Shared",
1658+
"group": "Automated",
1659+
"flagged": false
1660+
},
1661+
{
1662+
"number": "2.5.8",
1663+
"name": "Target Size (Minimum)",
1664+
"level": "AA",
1665+
"conformance": "Supports",
1666+
"responsibility": "Shared",
1667+
"group": "Automated",
1668+
"flagged": false
1669+
},
1670+
{
1671+
"number": "3.3.2",
1672+
"name": "Labels or Instructions",
1673+
"level": "A",
1674+
"conformance": "Supports",
1675+
"responsibility": "Shared",
1676+
"group": "Hybrid",
1677+
"flagged": false
1678+
},
1679+
{
1680+
"number": "4.1.2",
1681+
"name": "Name, Role, Value",
1682+
"level": "A",
1683+
"conformance": "Supports",
1684+
"responsibility": "Shared",
1685+
"group": "Hybrid",
1686+
"flagged": false
1687+
}
1688+
],
1689+
"summary": {
1690+
"rated": 15,
1691+
"levelA": 8,
1692+
"levelAA": 7,
1693+
"supports": 15,
1694+
"partiallySupports": 0,
1695+
"doesNotSupport": 0,
1696+
"verified": 14,
1697+
"automated": 5
1698+
}
1699+
},
15411700
{
15421701
"component": "LinearProgress",
15431702
"counts": {

‎packages/mui-material/src/FormControlLabel/FormControlLabel.test.js‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import FormControlLabel, {
66
} from '@mui/material/FormControlLabel';
77
import Checkbox from '@mui/material/Checkbox';
88
import FormControl from '@mui/material/FormControl';
9+
import Radio from '@mui/material/Radio';
10+
import Switch from '@mui/material/Switch';
911
import Typography from '@mui/material/Typography';
1012
import describeConformance from '../../test/describeConformance';
1113

@@ -343,4 +345,86 @@ describe('<FormControlLabel />', () => {
343345

344346
expect(screen.getByTestId('control')).to.have.attribute('value', 'test');
345347
});
348+
349+
// Deterministic checks for the WCAG success criteria the FormControlLabel
350+
// report rates as the label's own. See ./accessibility.md.
351+
describe('WCAG 2.2 conformance', () => {
352+
it('2.5.3 Label in Name: a Checkbox exposes the visible label as its accessible name', () => {
353+
render(<FormControlLabel control={<Checkbox />} label="Email notifications" />);
354+
// getByRole with `name` only resolves if the accessible name matches the visible label.
355+
expect(screen.getByRole('checkbox', { name: 'Email notifications' })).not.to.equal(null);
356+
});
357+
358+
it('2.5.3 Label in Name: a Radio exposes the visible label as its accessible name', () => {
359+
render(<FormControlLabel control={<Radio />} value="standard" label="Standard shipping" />);
360+
361+
expect(screen.getByRole('radio', { name: 'Standard shipping' })).not.to.equal(null);
362+
});
363+
364+
it('2.5.3 Label in Name: a Switch exposes the visible label as its accessible name', () => {
365+
render(<FormControlLabel control={<Switch />} label="Dark mode" />);
366+
367+
expect(screen.getByRole('switch', { name: 'Dark mode' })).not.to.equal(null);
368+
});
369+
370+
it('2.5.3 Label in Name: the required asterisk is excluded from the accessible name', () => {
371+
render(<FormControlLabel required control={<Checkbox />} label="Accept the terms" />);
372+
373+
// The name is the label text; the asterisk is decorative and not in the name.
374+
expect(screen.getByRole('checkbox', { name: 'Accept the terms' })).not.to.equal(null);
375+
});
376+
377+
describe('4.1.2 Name, Role, Value', () => {
378+
it('exposes the control role with the label as its accessible name', () => {
379+
render(<FormControlLabel control={<Checkbox />} label="Subscribe" />);
380+
381+
expect(screen.getByRole('checkbox', { name: 'Subscribe' })).to.have.property(
382+
'checked',
383+
false,
384+
);
385+
});
386+
387+
it('forwards required to the control without adding the asterisk to the name', () => {
388+
const { container } = render(
389+
<FormControlLabel required control={<Checkbox />} label="Accept the terms" />,
390+
);
391+
const checkbox = screen.getByRole('checkbox', { name: 'Accept the terms' });
392+
393+
expect(checkbox).to.have.property('required', true);
394+
// The visible text carries the asterisk, but the control's name does not.
395+
expect(container.querySelector('label')).to.have.text('Accept the terms\u2009*');
396+
});
397+
});
398+
399+
it('toggles the wrapped control when the label text is clicked', async () => {
400+
const { user } = render(
401+
<FormControlLabel control={<Checkbox />} label="Email notifications" />,
402+
);
403+
const checkbox = screen.getByRole('checkbox', { name: 'Email notifications' });
404+
expect(checkbox).to.have.property('checked', false);
405+
406+
await user.click(screen.getByText('Email notifications'));
407+
expect(checkbox).to.have.property('checked', true);
408+
});
409+
410+
it('keeps the control before the label in the DOM for every labelPlacement', () => {
411+
['end', 'start', 'top', 'bottom'].forEach((labelPlacement) => {
412+
const { container, unmount } = render(
413+
<FormControlLabel
414+
control={<Checkbox />}
415+
label="Email notifications"
416+
labelPlacement={labelPlacement}
417+
/>,
418+
);
419+
const input = container.querySelector('input');
420+
const labelText = screen.getByText('Email notifications');
421+
422+
// DOM order is control then label regardless of the visual placement.
423+
// The control and the label are in separate subtrees, so the position
424+
// is exactly DOCUMENT_POSITION_FOLLOWING when the label comes after it.
425+
expect(input.compareDocumentPosition(labelText)).to.equal(Node.DOCUMENT_POSITION_FOLLOWING);
426+
unmount();
427+
});
428+
});
429+
});
346430
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"axe": "docs/data/material/components/form-control-label/form-control-label.a11y.json",
3+
"criteria": {
4+
"2.5.8": { "responsibility": "Shared" }
5+
},
6+
"notApplicable": [
7+
"1.4.11",
8+
"2.1.1",
9+
"2.1.2",
10+
"2.4.3",
11+
"2.4.7",
12+
"2.4.11",
13+
"2.5.2",
14+
"3.2.1",
15+
"3.2.2",
16+
"3.2.4"
17+
]
18+
}

0 commit comments

Comments
 (0)