Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"FormControlLabelA11yStates": {
"rules": {
"aria-allowed-attr": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-conditional-attr": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-deprecated-role": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-hidden-focus": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-prohibited-attr": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-required-attr": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-roles": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-valid-attr": {
"status": "pass",
"tags": ["wcag2a"]
},
"aria-valid-attr-value": {
"status": "pass",
"tags": ["wcag2a"]
},
"color-contrast": {
"status": "pass",
"tags": ["wcag2aa"]
},
"form-field-multiple-labels": {
"status": "pass",
"tags": ["wcag2a"]
},
"label": {
"status": "pass",
"tags": ["wcag2a"]
},
"nested-interactive": {
"status": "pass",
"tags": ["wcag2a"]
},
"target-size": {
"status": "pass",
"tags": ["wcag22aa"]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Each row counts only the criteria that **apply** to that component; criteria tha
| [Chip](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Chip/accessibility.md) | 13 | 11 | 24 | 14 | 9 | 1 | 15/24 | 5 |
| [CircularProgress](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/CircularProgress/accessibility.md) | 6 | 5 | 11 | 8 | 3 | 0 | 6/11 | 1 |
| [Fab](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Fab/accessibility.md) | 14 | 11 | 25 | 20 | 5 | 0 | 19/25 | 9 |
| [FormControlLabel](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/FormControlLabel/accessibility.md) | 8 | 7 | 15 | 15 | 0 | 0 | 14/15 | 6 |
| [FormGroup](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/FormGroup/accessibility.md) | 5 | 2 | 7 | 7 | 0 | 0 | 4/7 | 2 |
| [FormLabel](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/FormLabel/accessibility.md) | 7 | 6 | 13 | 11 | 2 | 0 | 10/13 | 4 |
| [IconButton](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/IconButton/accessibility.md) | 15 | 12 | 27 | 22 | 5 | 0 | 18/27 | 9 |
Expand Down
161 changes: 160 additions & 1 deletion docs/data/material/getting-started/accessibility/scorecard.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"standard": "WCAG 2.2 Level A and AA",
"componentCount": 20,
"componentCount": 21,
"totals": {
"rated": 32,
"supports": 18,
Expand Down Expand Up @@ -2278,6 +2278,165 @@
"automated": 9
}
},
{
"component": "FormControlLabel",
"counts": {
"supports": 15,
"partiallySupports": 0,
"doesNotSupport": 0,
"notApplicable": 40,
"flagged": 1,
"rated": 15
},
"gaps": [],
"criteria": [
{
"number": "1.3.1",
"name": "Info and Relationships",
"level": "A",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Hybrid",
"flagged": false
},
{
"number": "1.3.2",
"name": "Meaningful Sequence",
"level": "A",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Hybrid",
"flagged": false
},
{
"number": "1.3.3",
"name": "Sensory Characteristics",
"level": "A",
"conformance": "Supports",
"responsibility": "Author",
"group": "Manual",
"flagged": false
},
{
"number": "1.4.1",
"name": "Use of Color",
"level": "A",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Hybrid",
"flagged": true
},
{
"number": "1.4.3",
"name": "Contrast (Minimum)",
"level": "AA",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Hybrid",
"flagged": false
},
{
"number": "1.4.4",
"name": "Resize Text",
"level": "AA",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Automated",
"flagged": false
},
{
"number": "1.4.5",
"name": "Images of Text",
"level": "AA",
"conformance": "Supports",
"responsibility": "Author",
"group": "Manual",
"flagged": false
},
{
"number": "1.4.10",
"name": "Reflow",
"level": "AA",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Automated",
"flagged": false
},
{
"number": "1.4.12",
"name": "Text Spacing",
"level": "AA",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Automated",
"flagged": false
},
{
"number": "2.4.6",
"name": "Headings and Labels",
"level": "AA",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Hybrid",
"flagged": false
},
{
"number": "2.5.2",
"name": "Pointer Cancellation",
"level": "A",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Automated",
"flagged": false
},
{
"number": "2.5.3",
"name": "Label in Name",
"level": "A",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Automated",
"flagged": false
},
{
"number": "2.5.8",
"name": "Target Size (Minimum)",
"level": "AA",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Automated",
"flagged": false
},
{
"number": "3.3.2",
"name": "Labels or Instructions",
"level": "A",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Hybrid",
"flagged": false
},
{
"number": "4.1.2",
"name": "Name, Role, Value",
"level": "A",
"conformance": "Supports",
"responsibility": "Shared",
"group": "Hybrid",
"flagged": false
}
],
"summary": {
"rated": 15,
"levelA": 8,
"levelAA": 7,
"supports": 15,
"partiallySupports": 0,
"doesNotSupport": 0,
"verified": 14,
"automated": 6
}
},
{
"component": "FormGroup",
"counts": {
Expand Down
111 changes: 111 additions & 0 deletions packages/mui-material/src/FormControlLabel/FormControlLabel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import FormControlLabel, {
} from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox';
import FormControl from '@mui/material/FormControl';
import Radio from '@mui/material/Radio';
import Switch from '@mui/material/Switch';
import Typography from '@mui/material/Typography';
import describeConformance from '../../test/describeConformance';

Expand Down Expand Up @@ -343,4 +345,113 @@ describe('<FormControlLabel />', () => {

expect(screen.getByTestId('control')).to.have.attribute('value', 'test');
});

// Deterministic checks for the WCAG success criteria the FormControlLabel
// report rates as the label's own. See ./accessibility.md.
describe('WCAG 2.2 conformance', () => {
it('1.3.1 Info and Relationships: associates the control with its label by wrapping it', () => {
const { container } = render(
<FormControlLabel control={<Checkbox />} label="Email notifications" />,
);
const label = container.firstChild;

expect(label).to.have.tagName('label');
expect(label).to.contain(screen.getByRole('checkbox'));
expect(label).to.contain(screen.getByText('Email notifications'));
});

it('2.5.3 Label in Name: a Checkbox exposes the visible label as its accessible name', () => {
render(<FormControlLabel control={<Checkbox />} label="Email notifications" />);
// getByRole with `name` only resolves if the accessible name matches the visible label.
expect(screen.getByRole('checkbox', { name: 'Email notifications' })).not.to.equal(null);
});

it('2.5.3 Label in Name: a Radio exposes the visible label as its accessible name', () => {
render(<FormControlLabel control={<Radio />} value="standard" label="Standard shipping" />);

expect(screen.getByRole('radio', { name: 'Standard shipping' })).not.to.equal(null);
});

it('2.5.3 Label in Name: a Switch exposes the visible label as its accessible name', () => {
render(<FormControlLabel control={<Switch />} label="Dark mode" />);

expect(screen.getByRole('switch', { name: 'Dark mode' })).not.to.equal(null);
});

describe('4.1.2 Name, Role, Value', () => {
it('exposes the control role with the label as its accessible name', () => {
render(<FormControlLabel control={<Checkbox />} label="Subscribe" />);

expect(screen.getByRole('checkbox', { name: 'Subscribe' })).to.have.property(
'checked',
false,
);
});

it('forwards required to the control without adding the asterisk to the name', () => {
const { container } = render(
<FormControlLabel required control={<Checkbox />} label="Accept the terms" />,
);
const checkbox = screen.getByRole('checkbox', { name: 'Accept the terms' });

expect(checkbox).to.have.property('required', true);
// The visible text carries the asterisk, but the control's name does not.
expect(container.querySelector('label')).to.have.text('Accept the terms\u2009*');
});
});

it('toggles the wrapped control when the label text is clicked', async () => {
const { user } = render(
<FormControlLabel control={<Checkbox />} label="Email notifications" />,
);
const checkbox = screen.getByRole('checkbox', { name: 'Email notifications' });
expect(checkbox).to.have.property('checked', false);

await user.click(screen.getByText('Email notifications'));
expect(checkbox).to.have.property('checked', true);
});

it('2.5.2 Pointer Cancellation: a press on the label text does not toggle the control', async () => {
const { user } = render(
<React.Fragment>
<FormControlLabel control={<Checkbox />} label="Email notifications" />
<div data-testid="outside" />
</React.Fragment>,
);
const checkbox = screen.getByRole('checkbox', { name: 'Email notifications' });
const labelText = screen.getByText('Email notifications');

// The label is part of the target. Nothing toggles on the down event, and
// releasing away from the label cancels. A click activates on pointer up.
await user.pointer([
{ keys: '[MouseLeft>]', target: labelText },
{ target: screen.getByTestId('outside') },
{ keys: '[/MouseLeft]' },
]);
expect(checkbox).to.have.property('checked', false);

await user.click(labelText);
expect(checkbox).to.have.property('checked', true);
});

it('1.3.2 Meaningful Sequence: keeps the control before the label in the DOM for every labelPlacement', () => {
['end', 'start', 'top', 'bottom'].forEach((labelPlacement) => {
const { container, unmount } = render(
<FormControlLabel
control={<Checkbox />}
label="Email notifications"
labelPlacement={labelPlacement}
/>,
);
const input = container.querySelector('input');
const labelText = screen.getByText('Email notifications');

// DOM order is control then label regardless of the visual placement.
// The control and the label are in separate subtrees, so the position
// is exactly DOCUMENT_POSITION_FOLLOWING when the label comes after it.
expect(input.compareDocumentPosition(labelText)).to.equal(Node.DOCUMENT_POSITION_FOLLOWING);
unmount();
});
});
});
});
20 changes: 20 additions & 0 deletions packages/mui-material/src/FormControlLabel/accessibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"axe": "docs/data/material/components/form-control-label/form-control-label.a11y.json",
"criteria": {
"1.3.2": { "responsibility": "Shared", "group": "Hybrid" },
"2.5.2": { "responsibility": "Shared" },
"2.5.8": { "responsibility": "Shared" }
},
"notApplicable": [
"1.1.1",
"1.4.11",
"2.1.1",
"2.1.2",
"2.4.3",
"2.4.7",
"2.4.11",
"3.2.1",
"3.2.2",
"3.2.4"
]
}
Loading
Loading