w3c / html-aria

ARIA in HTML
https://w3c.github.io/html-aria/
Other
181 stars 48 forks source link

aria-checked shouldn't be a required for an element role=switch when the switch is created with checkbox #227

Closed mpnkhan closed 4 years ago

mpnkhan commented 4 years ago

There are multiple ways to create a switch component, div, span, button. We can also use native element like checkbox with role=switch. Here is an example with switch component with checkboxes http://hcm-sample.surge.sh. W3C docs say aria-checked is a required attribute for switch role. Validators like axe throw an error even though the checked state is exposed by browsers and read by screen readers. aria-checked shouldn't be an required attribute for <input type="checkbox role="switch"">

Screen Shot 2020-05-07 at 11 11 20 AM
JAWS-test commented 4 years ago

I suspect that for a switch based on a checkbox the requirement "required attribute: aria-checked" is automatically met because each checkbox has implicitly aria-checked=true or aria-checked=false (see https://w3c.github.io/html-aam/#el-input-checkbox).

So the error is probably caused by validators like axe and a ticket should be created there

scottaohara commented 4 years ago

This is not an issue with this document, but rather with validators as @JAWS-test mentions.

As ARIA in HTML already mentions:

Note: the HTML checked attribute may be used instead of the aria-checked attribute for menuitemcheckbox, option or switch when used on type=checkbox.

If you are finding axe is throwing an error, then you can file a bug against that tool.

mpnkhan commented 4 years ago

Nope, the bug is about the document https://w3c.github.io/html-aria/#index-aria-switch and https://www.w3.org/TR/wai-aria-1.1/#switch which says aria-checked is required attribute. "The aria-checked attribute of a switch indicates whether the input is on (true) or off (false). The mixed value is invalid, and user agents MUST treat a mixed value as equivalent to false for this role.".
The document should explicitly state that aria-checked shouldn't be needed for checkbox elements. Did i misunderstood?

mpnkhan commented 4 years ago

Also filed https://github.com/dequelabs/axe-core/issues/2225 .