diff --git a/docs/data/material/components/button-group/button-group.a11y.json b/docs/data/material/components/button-group/button-group.a11y.json new file mode 100644 index 00000000000000..7d811e2e21a8b7 --- /dev/null +++ b/docs/data/material/components/button-group/button-group.a11y.json @@ -0,0 +1,442 @@ +{ + "BasicButtonGroup": { + "rules": { + "aria-allowed-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-conditional-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-deprecated-role": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + }, + "ButtonGroupA11ySemanticStates": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "link-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + }, + "DisableElevation": { + "rules": { + "aria-allowed-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-conditional-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-deprecated-role": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + }, + "GroupOrientation": { + "rules": { + "aria-allowed-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-conditional-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-deprecated-role": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + }, + "GroupSizesColors": { + "rules": { + "aria-allowed-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-conditional-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-deprecated-role": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + }, + "LoadingButtonGroup": { + "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-progressbar-name": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "duplicate-id-aria": { + "status": "pass", + "tags": ["wcag2a"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + }, + "SplitButton": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + }, + "VariantButtonGroup": { + "rules": { + "aria-allowed-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-conditional-attr": { + "status": "pass", + "tags": ["wcag2a"] + }, + "aria-deprecated-role": { + "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"] + }, + "button-name": { + "status": "pass", + "tags": ["wcag2a"] + }, + "color-contrast": { + "status": "pass", + "tags": ["wcag2aa"] + }, + "nested-interactive": { + "status": "pass", + "tags": ["wcag2a"] + }, + "target-size": { + "status": "pass", + "tags": ["wcag22aa"] + } + } + } +} diff --git a/docs/data/material/components/button-group/demos/split-button/SplitButton.tsx b/docs/data/material/components/button-group/demos/split-button/SplitButton.tsx index f0980fe079fcb9..073c3d1de20e37 100644 --- a/docs/data/material/components/button-group/demos/split-button/SplitButton.tsx +++ b/docs/data/material/components/button-group/demos/split-button/SplitButton.tsx @@ -55,7 +55,7 @@ export default function SplitButton() { + + , + ); + + const group = screen.getByRole('group'); + screen.getAllByRole('button').forEach((button) => { + expect(group).to.contain(button); + }); + }); + }); + + describe('2.4.3 Focus Order', () => { + it('moves through the buttons in DOM order', async () => { + const { user } = render( + + + + + , + ); + + for (const name of ['One', 'Two', 'Three']) { + // eslint-disable-next-line no-await-in-loop + await user.tab(); + expect(screen.getByRole('button', { name })).toHaveFocus(); + } + }); + + it('removes the buttons of a disabled group from the tab order', async () => { + const { user } = render( + + + + + + + + , + ); + + await user.tab(); + await user.tab(); + expect(screen.getByRole('button', { name: 'After' })).toHaveFocus(); + }); + }); + + // JSDOM doesn't support :focus-visible + it.skipIf(isJsdom())( + '2.4.7 Focus Visible: with the theme ring, the focused button paints above its neighbors', + async () => { + const { user } = render( + + + + + + , + ); + + await user.tab(); + const focused = screen.getByRole('button', { name: 'One' }); + expect(focused).to.have.class(buttonClasses.focusVisible); + // The neighbors overlap by 1px, so a lower z-index would cover the ring edge. + expect(window.getComputedStyle(focused).zIndex).to.equal('1'); + expect( + window.getComputedStyle(screen.getByRole('button', { name: 'Two' })).zIndex, + ).to.equal('auto'); + }, + ); + + describe('4.1.2 Name, Role, Value', () => { + it('has the group role and the name from aria-label', () => { + render( + + + , + ); + + expect(screen.getByRole('group')).toHaveAccessibleName('Export format'); + }); + + it('passes the disabled state to each button', () => { + render( + + + + , + ); + + screen.getAllByRole('button').forEach((button) => { + expect(button).to.have.property('disabled', true); + }); + }); + + it('keeps a button enabled when it sets disabled={false} in a disabled group', () => { + render( + + + + , + ); + + expect(screen.getByRole('button', { name: 'One' })).to.have.property('disabled', false); + expect(screen.getByRole('button', { name: 'Two' })).to.have.property('disabled', true); + }); + }); + }); }); diff --git a/packages/mui-material/src/ButtonGroup/accessibility.json b/packages/mui-material/src/ButtonGroup/accessibility.json new file mode 100644 index 00000000000000..07bb0392fc3fe7 --- /dev/null +++ b/packages/mui-material/src/ButtonGroup/accessibility.json @@ -0,0 +1,15 @@ +{ + "axe": "docs/data/material/components/button-group/button-group.a11y.json", + "inherits": "Button", + "criteria": { + "1.3.1": {}, + "1.3.2": { "responsibility": "Shared", "flagged": true }, + "1.4.4": {}, + "1.4.10": { "conformance": "Partially Supports" }, + "1.4.11": { "group": "Manual" }, + "1.4.12": {}, + "2.4.6": { "group": "Manual", "flagged": true }, + "2.4.7": {}, + "4.1.2": {} + } +} diff --git a/packages/mui-material/src/ButtonGroup/accessibility.md b/packages/mui-material/src/ButtonGroup/accessibility.md new file mode 100644 index 00000000000000..fd08ff083f6065 --- /dev/null +++ b/packages/mui-material/src/ButtonGroup/accessibility.md @@ -0,0 +1,271 @@ + + +# ButtonGroup accessibility conformance + +Rated against WCAG 2.2 Level A and AA. See the [reports legend](../accessibility.md). + + + +A ButtonGroup puts several Buttons in one set. This report rates only what the group adds: the group role and name, the layout, the dividers, and the focus order. Each button inherits the [Button report](../Button/accessibility.md). + + + +| Result | Count | +| :----------------------- | :---- | +| ✅ Supports | 7 | +| ⚠️ Partially Supports | 2 | +| ❌ Does Not Support | 0 | +| ➖ Not Applicable | 27 | +| ↗ Inherited (see Button) | 19 | +| 🚩 Flagged | 3/9 | + +## Known gaps + +- ⚠️ **1.4.10 Reflow.** A horizontal group does not wrap. A wide group makes the page scroll horizontally at 320 px. Set `orientation="vertical"` on small screens. +- ⚠️ **1.4.11 Non-text Contrast.** The buttons keep the Button focus ripple as their default focus indicator. Its contrast can fall below `3:1`. Enable `focusVisible` in the theme to get a ring. Avoid `disableRipple` and `disableFocusRipple` on the group, because they remove the indicator from every button. +- Inherits ⚠️ **1.4.3 Contrast (Minimum)** from [Button](../Button/accessibility.md). +- Inherits ⚠️ **2.2.2 Pause, Stop, Hide** from [Button](../Button/accessibility.md). +- Inherits ⚠️ **2.4.3 Focus Order** from [Button](../Button/accessibility.md). +- Inherits ⚠️ **4.1.3 Status Messages** from [Button](../Button/accessibility.md). + +## Success criteria + +### 🔍 Manual + +#### 1.3.2 Meaningful Sequence · A + +`🚩` · `✅ Supports` · `◐ Shared` + + + +- The group shows its buttons in DOM order, in a row or in a column. It does not reverse the order. +- The order of the children is an author decision. + +**Manual testing steps** + +1. Press Tab through a horizontal group. +2. Press Tab through a vertical group. +3. Compare the focus order with the visual order in each group. +4. Read each group with the screen-reader virtual cursor. + + + +**Pass:** focus and the reading order move in the reading direction in a horizontal group, and from top to bottom in a vertical group. + +#### 1.4.11 Non-text Contrast · AA + +`🚩` · `⚠️ Partially Supports` · `● Component` + + + +- The dividers between the buttons have these contrasts against the adjacent colors, in light mode: + - `outlined` and `text`: the `main` color at `50%` on a white page, `1.76:1` (`warning`) to `2.39:1` (`secondary`). With `color="inherit"`, `1.74:1`. + - `contained`: the `dark` color between two `main` fills, `1.13:1` (`error`) to `1.92:1` (`info`). With `color="inherit"`, `grey[400]` on `grey[300]` is `1.42:1`. +- In an `outlined` group, the divider is the border of the next button. So the `outlined` border has the same contrast. +- WCAG does not require a boundary when text or an icon identifies the control (Understanding 1.4.11). Each button has its own label, so the dividers do not need `3:1`. +- The focus indicator is the Button focus ripple. `disableRipple` and `disableFocusRipple` on the group pass to each button, so one group prop can remove the indicator from all buttons. `disableElevation` removes the focus shadow of a `contained` button. + +**Manual testing steps** + +1. With a contrast checker, measure the dividers of each variant in use against the colors next to them. +2. Measure the `outlined` border against the page. +3. Press Tab to a button in the group. +4. Measure the focus indicator against the colors next to it. + + + +**Pass:** each button can be identified by its label, and the focus indicator is at least `3:1`. + +#### 2.4.6 Headings and Labels · AA + +`🚩` · `✅ Supports` · `◐ Shared` + + + +- The group name, from `aria-label`, describes the purpose of the set of buttons. Each button keeps its own label. +- Whether the group name is useful is an authoring concern. + +**Manual testing steps** + +1. List the `aria-label` of each ButtonGroup. +2. Read each name without the buttons. + + + +**Pass:** each group name tells the purpose of the set, for example "Text alignment", not "Basic button group". + +### 🔁 Hybrid + +#### 1.3.1 Info and Relationships · A + +`✅ Supports` · `◐ Shared` + +Tested by: unit `ButtonGroup.test.js` + + + +- The root has `role="group"`, so assistive technology reports the buttons as one set. A unit test confirms that the buttons are inside the group element. An author can replace it with the `role` prop. +- The author names the group with `aria-label` or `aria-labelledby`. The component does not warn when the name is missing. A group without a name still conveys the grouping. + +**Manual testing steps** + +1. Start a screen reader (NVDA with Chrome, or VoiceOver with Safari). +2. Press Tab into a ButtonGroup that has an `aria-label`. +3. Listen to the announcement. +4. Do the test again with a group that has no `aria-label`. + + + +**Pass:** the screen reader announces the group role and name, and the name and role of the button. A group with no name is announced as a group. + +#### 2.4.7 Focus Visible · AA + +`✅ Supports` · `◐ Shared` + +Tested by: unit `ButtonGroup.test.js` · Playwright + + + +- Keyboard focus shows the Button focus ripple, inside the button, so the neighbors cannot cover it. A Playwright test confirms that keyboard focus changes how the button looks. +- In a `contained` group without the theme ring, the focused button also gets a shadow. The next button can cover the edge of this shadow. +- With `focusVisible: true` on the theme, the focused button gets the outline ring and `z-index: 1`. The neighbors touch the focused button. In an `outlined` group, they overlap it by 1 px. The ring paints above them. A unit test in a real browser confirms the `z-index`. In a `contained` group, the ring replaces the shadow. +- `disableRipple` or `disableFocusRipple` on the group removes the ripple from each button. + +**Manual testing steps** + +1. Press Tab through the buttons of a horizontal and a vertical group. +2. Make sure that the focus indicator of each button is fully visible. +3. Set `focusVisible: true` on the theme and do the test again. + + + +**Pass:** the focus indicator of each button is fully visible, and the adjacent buttons do not cover the ring. + +#### 4.1.2 Name, Role, Value · A + +`✅ Supports` · `◐ Shared` + +Tested by: unit `ButtonGroup.test.js` · axe-core `aria-allowed-attr` ✅, `aria-conditional-attr` ✅, `aria-deprecated-role` ✅, `aria-hidden-focus` ✅, `aria-prohibited-attr` ✅, `aria-required-attr` ✅, `aria-roles` ✅, `aria-valid-attr` ✅, `aria-valid-attr-value` ✅, `button-name` ✅, `duplicate-id-aria` ✅, `link-name` ✅, `nested-interactive` ✅ + + + +- The group has `role="group"` and the name from `aria-label`. `disabled` on the group disables each button that does not set its own `disabled` prop. A button with `disabled={false}` stays enabled. Unit tests confirm this. The axe-core ARIA rules pass on the demos. +- The group does not keep a pressed or selected state. For a set of toggles, the author sets `aria-pressed` on each button, as in the `ButtonGroupA11ySemanticStates` fixture, or uses ToggleButtonGroup. axe-core checks these attributes on the fixture. +- In a split button, the author sets `aria-haspopup="menu"`, `aria-expanded`, and `aria-label` on the arrow button. The SplitButton demo and the `ButtonGroupA11ySemanticStates` fixture show this pattern. + +**Manual testing steps** + +1. Start a screen reader. +2. Press Tab to the arrow button of the SplitButton demo. +3. Listen to the announcement. +4. Press Enter to open the menu. +5. Press Shift+Tab to move focus back to the arrow button. +6. Listen to the announcement again. + + + +**Pass:** the arrow button announces its name, that it opens a menu, and "collapsed" or "expanded". + +### ⚙️ Automated + +#### 1.4.4 Resize Text · AA + +`✅ Supports` · `◐ Shared` + +Tested by: Playwright + + + +- The buttons scale with the text size, and the group grows with them. A Playwright test confirms that the variant demo does not clip or overflow at a 200% text size. + + + +#### 1.4.10 Reflow · AA + +`⚠️ Partially Supports` · `◐ Shared` + +Tested by: Playwright + + + +- A horizontal group is an `inline-flex` row that does not wrap. When the group is too wide, each button wraps its label first. When that is not enough, the group overflows its container, and the page scrolls horizontally. +- A Playwright test confirms that the three-button variant demo does not scroll at 320 px. A screenshot records the `ButtonGroupA11yWideGroup` fixture, with five buttons, at 320 px. The test viewer hides horizontal overflow, so the screenshot shows the group clipped at the right edge. +- The component does not reflow a wide horizontal group, so the rating is Partially Supports. To fix a wide group, set `orientation="vertical"` on small screens, for example with `useMediaQuery`. + + + +#### 1.4.12 Text Spacing · AA + +`✅ Supports` · `◐ Shared` + +Tested by: Playwright + + + +- The buttons wrap their labels, and the group grows with them. A Playwright test confirms this with the WCAG text-spacing values. + + + +## Inherited from Button + +- **1.1.1 Non-text Content (A).** +- **1.3.3 Sensory Characteristics (A).** +- **1.4.1 Use of Color (A).** +- **1.4.3 Contrast (Minimum) (AA).** +- **1.4.5 Images of Text (AA).** +- **2.1.1 Keyboard (A).** +- **2.1.2 No Keyboard Trap (A).** +- **2.2.2 Pause, Stop, Hide (A).** +- **2.4.3 Focus Order (A).** Each button is a tab stop in DOM order, in both orientations. A disabled group removes its buttons from the tab order. Unit tests in `ButtonGroup.test.js` confirm this. +- **2.4.4 Link Purpose (In Context) (A).** A grouped Button with `href`. The `ButtonGroupA11ySemanticStates` fixture has one, and axe-core `link-name` passes on it. +- **2.4.11 Focus Not Obscured (Minimum) (AA).** +- **2.5.2 Pointer Cancellation (A).** +- **2.5.3 Label in Name (A).** +- **2.5.8 Target Size (Minimum) (AA).** The group lowers the minimum width of each button to 40 px, which is still larger than 24 px. +- **3.2.1 On Focus (A).** +- **3.2.2 On Input (A).** +- **3.2.4 Consistent Identification (AA).** +- **3.3.2 Labels or Instructions (A).** Applies only to a grouped file-upload Button. +- **4.1.3 Status Messages (AA).** A grouped Button with `loading`, as in the `LoadingButtonGroup` demo. + +## Not applicable + +- **1.2.1 Audio-only and Video-only (Prerecorded) (A), 1.2.2 Captions (Prerecorded) (A), 1.2.3 Audio Description or Media Alternative (Prerecorded) (A), 1.2.4 Captions (Live) (AA), 1.2.5 Audio Description (Prerecorded) (AA).** No audio or video. +- **1.3.4 Orientation (AA).** Sets no orientation lock; a layout concern. +- **1.3.5 Identify Input Purpose (AA).** Collects no information about the user through `autocomplete`. +- **1.4.2 Audio Control (A).** Emits no audio. +- **1.4.13 Content on Hover or Focus (AA).** Shows no additional content on hover or focus; a `Tooltip` wrapper would own this. +- **2.1.4 Character Key Shortcuts (A).** Binds no single-character keyboard shortcut. +- **2.2.1 Timing Adjustable (A).** Sets no time limit. +- **2.3.1 Three Flashes or Below Threshold (A).** Nothing flashes. +- **2.4.1 Bypass Blocks (A), 2.4.2 Page Titled (A), 2.4.5 Multiple Ways (AA).** Page or site structure, not a single component. +- **2.5.1 Pointer Gestures (A), 2.5.4 Motion Actuation (A).** Activates on a simple click; reads no device motion. +- **2.5.7 Dragging Movements (AA).** No drag interactions. +- **3.1.1 Language of Page (A), 3.1.2 Language of Parts (AA).** The component emits no `` and no text of its own. A foreign-language label is the author's phrase to mark. +- **3.2.3 Consistent Navigation (AA).** Covers repeated navigation across a set of pages, not a single component. +- **3.2.6 Consistent Help (A).** Covers consistent placement of help across pages. +- **3.3.1 Error Identification (A), 3.3.3 Error Suggestion (AA), 3.3.4 Error Prevention (Legal, Financial, Data) (AA).** Collects and validates no input; these belong to the form or process. +- **3.3.7 Redundant Entry (A).** Captures no previously entered data to repopulate. +- **3.3.8 Accessible Authentication (Minimum) (AA).** No authentication step; the duty falls on the credential fields. + +## Level AAA + + + +- **2.4.13 Focus Appearance.** The buttons keep the Button focus ripple, which does not meet it. `🚩` +- **2.5.5 Target Size (Enhanced), 44 px.** The buttons keep the Button sizes, which are less than 44 px high. `🚩` + + + +## Scope and test environment + +- **Standard.** WCAG 2.2, Level A and AA. +- **Component version.** `@mui/material` 10.0.0-alpha.0. + + + +- **Scope.** The ButtonGroup wrapper, rendered through its documented API. The buttons inside it inherit the [Button report](../Button/accessibility.md). +- **Automated.** axe-core in the Playwright test harness, on the ButtonGroup demos and fixtures in [`button-group.a11y.json`](../../../../docs/data/material/components/button-group/button-group.a11y.json). Interaction tests are in `ButtonGroup.test.js`. +- **Assistive-technology review.** Not done yet. The flagged criteria come from a review of the source. A review with NVDA, JAWS, and VoiceOver must still confirm them. + + diff --git a/packages/mui-material/src/ToggleButtonGroup/accessibility.json b/packages/mui-material/src/ToggleButtonGroup/accessibility.json index b2ab3a742dbb79..36cd4a018f49b9 100644 --- a/packages/mui-material/src/ToggleButtonGroup/accessibility.json +++ b/packages/mui-material/src/ToggleButtonGroup/accessibility.json @@ -3,7 +3,7 @@ "inherits": "ToggleButton", "criteria": { "1.3.1": {}, - "1.4.10": {}, + "1.4.10": { "conformance": "Partially Supports" }, "2.4.6": { "group": "Manual", "flagged": true }, "4.1.2": {} }, diff --git a/packages/mui-material/src/ToggleButtonGroup/accessibility.md b/packages/mui-material/src/ToggleButtonGroup/accessibility.md index 59826e2e21756f..73458180620da2 100644 --- a/packages/mui-material/src/ToggleButtonGroup/accessibility.md +++ b/packages/mui-material/src/ToggleButtonGroup/accessibility.md @@ -14,8 +14,8 @@ Unlike a radio group, ToggleButtonGroup adds no roving tab order and no arrow-ke | Result | Count | | :------------------------------ | :---- | -| ✅ Supports | 4 | -| ⚠️ Partially Supports | 0 | +| ✅ Supports | 3 | +| ⚠️ Partially Supports | 1 | | ❌ Does Not Support | 0 | | ➖ Not Applicable | 31 | | ↗ Inherited (see Toggle Button) | 20 | @@ -23,6 +23,7 @@ Unlike a radio group, ToggleButtonGroup adds no roving tab order and no arrow-ke ## Known gaps +- ⚠️ **1.4.10 Reflow.** A horizontal group does not wrap. A wide group makes the page scroll horizontally at 320 px. Set `orientation="vertical"` on small screens. - Inherits ⚠️ **1.4.1 Use of Color** from [Toggle Button](../ToggleButton/accessibility.md). - Inherits ⚠️ **1.4.3 Contrast (Minimum)** from [Toggle Button](../ToggleButton/accessibility.md). - Inherits ⚠️ **1.4.11 Non-text Contrast** from [Toggle Button](../ToggleButton/accessibility.md). @@ -97,14 +98,14 @@ Tested by: unit `ToggleButtonGroup.test.js` · axe-core `aria-allowed-attr` ✅, #### 1.4.10 Reflow · AA -`✅ Supports` · `◐ Shared` +`⚠️ Partially Supports` · `◐ Shared` Tested by: Playwright - Each toggle sizes to its content, but the group owns the layout: a horizontal group is `display: inline-flex` and does not wrap (`ToggleButtonGroup.js`), so a wide row of toggles can overflow horizontally at 320 CSS pixels. -- The component provides `orientation="vertical"` as the escape hatch; the author keeps the group within 320 pixels by switching orientation or limiting the number of toggles. Covered by a Playwright test at a 320px viewport. +- The component does not reflow a wide horizontal group, so the rating is Partially Supports. To fix a wide group, set `orientation="vertical"` on small screens, or use fewer toggles. A Playwright test checks the demos at a 320px viewport. diff --git a/packages/mui-material/src/accessibility.md b/packages/mui-material/src/accessibility.md index 1384ca671ef17e..4763f281b08292 100644 --- a/packages/mui-material/src/accessibility.md +++ b/packages/mui-material/src/accessibility.md @@ -187,6 +187,7 @@ Edit the JSON files, not this table. | [AccordionSummary](./AccordionSummary/accessibility.md) | 23 | 1 | 0 | 31 | — | 3/24 | | [Avatar](./Avatar/accessibility.md) | 9 | 2 | 0 | 44 | — | 4/11 | | [Button](./Button/accessibility.md) | 23 | 5 | 0 | 27 | — | 9/28 | +| [ButtonGroup](./ButtonGroup/accessibility.md) | 7 | 2 | 0 | 27 | 19 | 3/9 | | [Checkbox](./Checkbox/accessibility.md) | 24 | 1 | 0 | 30 | — | 3/25 | | [CircularProgress](./CircularProgress/accessibility.md) | 8 | 3 | 0 | 44 | — | 5/11 | | [Fab](./Fab/accessibility.md) | 21 | 4 | 0 | 30 | — | 6/25 | @@ -199,7 +200,7 @@ Edit the JSON files, not this table. | [Switch](./Switch/accessibility.md) | 24 | 1 | 0 | 30 | — | 2/25 | | [TextField](./TextField/accessibility.md) | 25 | 3 | 0 | 27 | — | 4/28 | | [ToggleButton](./ToggleButton/accessibility.md) | 21 | 3 | 0 | 31 | — | 2/24 | -| [ToggleButtonGroup](./ToggleButtonGroup/accessibility.md) | 4 | 0 | 0 | 31 | 20 | 1/4 | +| [ToggleButtonGroup](./ToggleButtonGroup/accessibility.md) | 3 | 1 | 0 | 31 | 20 | 1/4 | diff --git a/packages/mui-material/src/manual-testing.md b/packages/mui-material/src/manual-testing.md index bf9694e00a4022..8930a4576c99f1 100644 --- a/packages/mui-material/src/manual-testing.md +++ b/packages/mui-material/src/manual-testing.md @@ -80,6 +80,17 @@ Run the rows matching what you touched, for the component you touched. - [ ] 🔁 **4.1.2 Name, Role, Value** — name, role, and state are correct for every variant, and state changes are announced. - [ ] 🔍 **4.1.3 Status Messages** — the change is announced without the user moving focus to it. It is not, because the component adds no live region; wrap the status in `role="status"` to fix it. +## ButtonGroup + +6 checks · full procedures in [`ButtonGroup/accessibility.md`](./ButtonGroup/accessibility.md) + +- [ ] 🔁 **1.3.1 Info and Relationships** — the screen reader announces the group role and name, and the name and role of the button. A group with no name is announced as a group. +- [ ] 🔍 **1.3.2 Meaningful Sequence** — focus and the reading order move in the reading direction in a horizontal group, and from top to bottom in a vertical group. +- [ ] 🔍 **1.4.11 Non-text Contrast** — each button can be identified by its label, and the focus indicator is at least `3:1`. +- [ ] 🔍 **2.4.6 Headings and Labels** — each group name tells the purpose of the set, for example "Text alignment", not "Basic button group". +- [ ] 🔁 **2.4.7 Focus Visible** — the focus indicator of each button is fully visible, and the adjacent buttons do not cover the ring. +- [ ] 🔁 **4.1.2 Name, Role, Value** — the arrow button announces its name, that it opens a menu, and "collapsed" or "expanded". + ## Checkbox 9 checks · full procedures in [`Checkbox/accessibility.md`](./Checkbox/accessibility.md) diff --git a/scripts/a11yScorecard/index.mjs b/scripts/a11yScorecard/index.mjs index 71f8f1169420cc..c83508bc041e7c 100644 --- a/scripts/a11yScorecard/index.mjs +++ b/scripts/a11yScorecard/index.mjs @@ -114,7 +114,7 @@ async function run(argv) { summary: summarize(report.criteria), })); fail([ - ...reports.flatMap((report) => validateReport(report, check)), + ...reports.flatMap((report) => validateReport(report, check, defaults)), ...validateKnownGaps(knownGaps, reports, check), ]); const criteria = rollUpCriteria(reports); diff --git a/scripts/a11yScorecard/rollup.mjs b/scripts/a11yScorecard/rollup.mjs index e055f9eb641d44..7586c3e3823038 100644 --- a/scripts/a11yScorecard/rollup.mjs +++ b/scripts/a11yScorecard/rollup.mjs @@ -22,17 +22,23 @@ const ratingOf = (fields) => Object.fromEntries(RATING_KEYS.map((key) => [key, f * criterion unless its own `notApplicable` lists it or it is not applicable by * default. Keying a default not-applicable criterion in `criteria` rates it. A * component with `inherits` rates only the criteria it keys, and inherits the - * rest that its parent rates. + * rest that its parent rates, including default not-applicable ones. Its own + * `notApplicable` takes precedence over both, so it can opt out of a criterion + * that the parent rates. */ function resolveReport(source, defaults, resolveParent) { const { component, data, regions, axe, ownTests, extraTests } = source; const overrides = data.criteria; const ownNotApplicable = new Set(data.notApplicable ?? []); + const parent = data.inherits ? resolveParent(data.inherits) : null; + // A criterion the parent rates stays applicable, even when it is not applicable by default. + const parentRates = new Set((parent?.criteria ?? []).map(({ number }) => number)); const isNotApplicable = (number) => ownNotApplicable.has(number) || - (Boolean(defaults.data.criteria[number]?.notApplicable) && !(number in overrides)); + (Boolean(defaults.data.criteria[number]?.notApplicable) && + !(number in overrides) && + !parentRates.has(number)); - const parent = data.inherits ? resolveParent(data.inherits) : null; const rates = (number) => !isNotApplicable(number) && (parent ? number in overrides : true); const unitRefs = new Map(); @@ -108,6 +114,8 @@ function resolveReport(source, defaults, resolveParent) { .map(({ number }) => parentRated.get(number)) .filter((criterion) => criterion.conformance !== 'Supports'), }, + // The criteria that the parent rates. `validateReport` reads it, so the two cannot drift. + parentRates, playwright: [...playwright], unaccounted: WCAG_CRITERIA.filter( ({ number }) => diff --git a/scripts/a11yScorecard/validate.mjs b/scripts/a11yScorecard/validate.mjs index 5bea0df0ed0eea..6e0fbbd6877d41 100644 --- a/scripts/a11yScorecard/validate.mjs +++ b/scripts/a11yScorecard/validate.mjs @@ -184,7 +184,8 @@ export async function validateSource(source, defaults) { for (const number of ownNotApplicable) { if (!defaults.data.criteria[number]) { violations.push(`notApplicable: ${number} is not a WCAG 2.2 Level A or AA criterion`); - } else if (defaults.data.criteria[number].notApplicable) { + } else if (defaults.data.criteria[number].notApplicable && !data.inherits) { + // `validateReport` checks an inheriting component against its parent. violations.push(`notApplicable: ${number} is already not applicable by default`); } } @@ -305,10 +306,20 @@ export function validateKnownGaps(knownGaps, reports, check) { * Returns every problem in one resolved report, prefixed with the component * name. With `check`, the prose the report needs must also be written. */ -export function validateReport(report, check) { - const { component, data, regions } = report; +export function validateReport(report, check, defaults) { + const { component, data, regions, parentRates } = report; const violations = []; + // An inheriting component can opt out of a default not-applicable criterion + // only when its parent rates that criterion. + if (data.inherits) { + for (const number of data.notApplicable ?? []) { + if (defaults.data.criteria[number]?.notApplicable && !parentRates.has(number)) { + violations.push(`notApplicable: ${number} is already not applicable by default`); + } + } + } + for (const number of report.unaccounted) { violations.push(`${number} is not rated, inherited, or not applicable`); } diff --git a/test/regressions/a11y/criteriaSuites.mjs b/test/regressions/a11y/criteriaSuites.mjs index 7a7744ea4a8a38..214f9eb1a7f1f5 100644 --- a/test/regressions/a11y/criteriaSuites.mjs +++ b/test/regressions/a11y/criteriaSuites.mjs @@ -18,6 +18,7 @@ export const CSS_LAYOUT_SUITES = [ textOnlyResize: false, }, { component: 'Button', route: '/docs-components-buttons/BasicButtons' }, + { component: 'ButtonGroup', route: '/docs-components-button-group/VariantButtonGroup' }, { component: 'Checkbox', route: '/docs-components-checkboxes/Checkboxes' }, { component: 'CircularProgress', @@ -68,6 +69,11 @@ export const FOCUS_VISIBLE_TARGETS = [ route: '/docs-components-buttons/BasicButtons', selector: '.MuiButton-root', }, + { + component: 'ButtonGroup', + route: '/docs-components-button-group/BasicButtonGroup', + selector: '.MuiButtonGroup-grouped', + }, { component: 'Checkbox', route: '/docs-components-checkboxes/Checkboxes', diff --git a/test/regressions/a11y/fixtures/button-group/ButtonGroupA11ySemanticStates.js b/test/regressions/a11y/fixtures/button-group/ButtonGroupA11ySemanticStates.js new file mode 100644 index 00000000000000..8e2187da99fbb9 --- /dev/null +++ b/test/regressions/a11y/fixtures/button-group/ButtonGroupA11ySemanticStates.js @@ -0,0 +1,43 @@ +import Stack from '@mui/material/Stack'; +import Button from '@mui/material/Button'; +import ButtonGroup from '@mui/material/ButtonGroup'; +import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; +import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; +import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; + +export default function ButtonGroupA11ySemanticStates() { + return ( + + + + + + + + + + + + + + + + + + + + {/* The split button pattern, with `aria-expanded` set while the menu is closed. */} + + + + + + ); +} diff --git a/test/regressions/a11y/fixtures/button-group/ButtonGroupA11yWideGroup.js b/test/regressions/a11y/fixtures/button-group/ButtonGroupA11yWideGroup.js new file mode 100644 index 00000000000000..4f60e67f8f1739 --- /dev/null +++ b/test/regressions/a11y/fixtures/button-group/ButtonGroupA11yWideGroup.js @@ -0,0 +1,16 @@ +import Button from '@mui/material/Button'; +import ButtonGroup from '@mui/material/ButtonGroup'; + +// A horizontal group wider than 320 CSS px (1.4.10). The group does not wrap. +// The test viewer hides horizontal overflow, so the screenshot shows it clipped. +export default function ButtonGroupA11yWideGroup() { + return ( + + + + + + + + ); +} diff --git a/test/regressions/demoMeta.test.ts b/test/regressions/demoMeta.test.ts index 5b8638380b91f6..adb659c6f041e7 100644 --- a/test/regressions/demoMeta.test.ts +++ b/test/regressions/demoMeta.test.ts @@ -118,6 +118,30 @@ describe('getConfig', () => { }); }); + it('records the wide ButtonGroup fixture at 320 px, without axe', () => { + expect( + getConfig(A11Y_RULES, 'test/regressions/a11y/fixtures/button-group/ButtonGroupA11yWideGroup'), + ).to.equal(undefined); + expect( + getConfig( + SCREENSHOT_RULES, + 'test/regressions/a11y/fixtures/button-group/ButtonGroupA11yWideGroup', + ), + ).to.deep.include({ enabled: true, viewportWidth: 320 }); + }); + + it('asserts every rule on the enrolled ButtonGroup demos and fixture', () => { + expect( + getConfig(A11Y_RULES, 'docs/data/material/components/button-group/SplitButton'), + ).to.deep.include({ enabled: true, assertions: 'all' }); + expect( + getConfig( + A11Y_RULES, + 'test/regressions/a11y/fixtures/button-group/ButtonGroupA11ySemanticStates', + ), + ).to.deep.include({ enabled: true, assertions: 'all' }); + }); + it('asserts every rule on the enrolled Fab demos and fixtures', () => { expect( getConfig( diff --git a/test/regressions/demoMeta.ts b/test/regressions/demoMeta.ts index a52a7062ff6cca..7f8d624dabd0df 100644 --- a/test/regressions/demoMeta.ts +++ b/test/regressions/demoMeta.ts @@ -167,6 +167,11 @@ export const SCREENSHOT_RULES: ScreenshotRule[] = [ { test: 'test/regressions/a11y/fixtures/**', enabled: false }, // A11y-only coverage fixtures { test: 'test/regressions/a11y/fixtures/buttons/ButtonA11yTextSpacing', enabled: true }, // Visual regression for text spacing (1.4.12); adds no unique axe coverage { test: 'test/regressions/a11y/fixtures/accordion/AccordionA11yTextSpacing', enabled: true }, // Visual regression for text spacing (1.4.12); adds no unique axe coverage + { + test: 'test/regressions/a11y/fixtures/button-group/ButtonGroupA11yWideGroup', + enabled: true, + viewportWidth: 320, + }, // Visual record of a wide horizontal group, clipped at 320 CSS px (1.4.10) { test: 'test/regressions/a11y/fixtures/floating-action-button/FabA11yLongLabel', enabled: true, @@ -291,6 +296,18 @@ const BUTTON_A11Y_DEMOS = [ 'CustomizedButtons', ]; +// ButtonGroup docs demos enrolled for axe assertions. SplitButton renders only the +// closed menu button; the open menu needs interaction. +const BUTTON_GROUP_A11Y_DEMOS = [ + 'BasicButtonGroup', + 'VariantButtonGroup', + 'GroupSizesColors', + 'GroupOrientation', + 'DisableElevation', + 'LoadingButtonGroup', + 'SplitButton', +]; + // Fab docs demos enrolled for axe assertions. FloatingActionButtonZoom is excluded: // most of its content is a Tabs component. const FAB_A11Y_DEMOS = [ @@ -443,6 +460,20 @@ export const A11Y_RULES: A11yRule[] = [ assertions: 'all', skipAssertions: ['color-contrast'], }, + { + test: `docs/data/material/components/button-group/{${BUTTON_GROUP_A11Y_DEMOS.join(',')}}`, + enabled: true, + assertions: 'all', + }, + // An a11y-only fixture under `test/regressions/a11y/fixtures/button-group/`; the + // suite name maps its results into the same `button-group.a11y.json`. + // `ButtonGroupA11yWideGroup` is not enrolled. It has only plain buttons, and + // it exists only for the 320 px screenshot. + { + test: 'test/regressions/a11y/fixtures/button-group/ButtonGroupA11ySemanticStates', + enabled: true, + assertions: 'all', + }, { test: `docs/data/material/components/floating-action-button/{${FAB_A11Y_DEMOS.join(',')}}`, enabled: true,