From b2d636f14dcd33313f6604cfd4a64b542c831b34 Mon Sep 17 00:00:00 2001 From: Shawn Taylor Date: Wed, 6 Mar 2024 17:34:54 -0500 Subject: [PATCH] fix(checkbox): set aria-checked of indeterminate checkbox to 'mixed' (#29115) Issue number: resolves Internal --------- ## What is the current behavior? We are not ever explicitly setting `aria-checked`. For checked and unchecked states (i.e. `true` and `false` for aria-checked), we don't need to set `aria-checked` because an input with a type of 'checkbox' has built-in semantics making `aria-checked` redundant. However, when the checkbox is in an indeterminate state, `aria-checked` should have a value of 'mixed'. We are not currently ever setting it to 'mixed'. See [MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-checked#description) for more details. ## What is the new behavior? - The checkbox's `aria-checked` has a value of 'true' when it is checked - The checkbox's `aria-checked` has a value of 'false' when it is unchecked - The checkbox's `aria-checked` has a value of 'mixed' when it is indeterminate ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information --- core/src/components/checkbox/checkbox.tsx | 1 + .../src/components/checkbox/test/checkbox.spec.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/core/src/components/checkbox/checkbox.tsx b/core/src/components/checkbox/checkbox.tsx index ab65f51a83..b05110a245 100644 --- a/core/src/components/checkbox/checkbox.tsx +++ b/core/src/components/checkbox/checkbox.tsx @@ -251,6 +251,7 @@ export class Checkbox implements ComponentInterface { return ( { expect(checkbox.checked).toBe(false); }); }); + +describe('ion-checkbox: indeterminate', () => { + it('should have a mixed value for aria-checked', async () => { + const page = await newSpecPage({ + components: [Checkbox], + html: ` + Checkbox + `, + }); + + const checkbox = page.body.querySelector('ion-checkbox')!; + + expect(checkbox.getAttribute('aria-checked')).toBe('mixed'); + }); +});