Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can you use aria-required with checkboxes? #1963

Closed
mbgower opened this issue Jul 15, 2021 · 10 comments
Closed

How can you use aria-required with checkboxes? #1963

mbgower opened this issue Jul 15, 2021 · 10 comments

Comments

@mbgower
Copy link
Contributor

mbgower commented Jul 15, 2021

I'm trying to provide guidance on checkboxes, and am wondering what to tell people about use of aria-required.
It is an allowed state, according to aria. However, since checkboxes are independent on one another, how can it be applied? The only case I can think of is a with a single checkbox ("I agree") where the user must select to continue. Is that the intended use case?

One approach I'd considered was its use on a group of checkboxes. If at least one checkbox in a set must be selected, I would have thought putting aria-required on the fieldset would be an approach; however, aria is specific that while radiogroup can take aria-required, group is not listed. And fieldset is also not showing up under the Used in Roles section.

I welcome comments.

PS If this is better posted on another project, please let me know

@fstrr
Copy link
Contributor

fstrr commented Jul 15, 2021

There's a useful blog post on accessible validation of checkbox and radio button groups from 2019 that covers this and suggests using fieldset. I had a quick look on the ARIA repo and couldn't find an issue for groups of required checkboxes, so I'll create one today. I'd meant to create one last year, but it never happened.

@mbgower
Copy link
Contributor Author

mbgower commented Jul 16, 2021

@fstrr, thanks for the response. While some of the test results with screen readers are interesting, this article didn't really provide me with new information entirely relevant. (They also neglected to mention/investigate live regions.)

Ultimately, they spend little time talking about required fields in checkboxes and focus more on instructions/errors. They do repeat my basic issue:

We did attempt using the radiogroup role, but there is no equivalent option for groups of checkboxes.

I'm still left with the basic questions:

  1. why is aria-required an allowed state for checkboxes?
  2. why isn't aria-required allowed for a group or fieldset?

@fstrr
Copy link
Contributor

fstrr commented Jul 16, 2021

@mbgower Sorry it wasn't more useful. I did raise an issue on the ARIA repo yesterday, but it got almost-instantly closed with a comment that this really needs to be part of the HTML spec. So now I'm going to do that. None of this solves your problem, unfortunately.

@patrickhlauke
Copy link
Member

patrickhlauke commented Jul 16, 2021

not had time to test, but ... add role="radiogroup" to the <fieldset>? [edit: finishing that thought...and then adding aria-required="true" on the <fieldset>]

@patrickhlauke
Copy link
Member

related, looking at the actual HTML spec, that second example is...very bizarre https://html.spec.whatwg.org/multipage/input.html#attr-input-required - if i understand it correctly, it's saying that if any radio input in a group is set to required, the whole group becomes required?

@mbgower
Copy link
Contributor Author

mbgower commented Jul 16, 2021

@patrickhlauke main goal is to understand how checkboxes are intended to work with respect to aria. I get how radio buttons work.
Wondering why there is no group feature for checkboxes (e.g., I want at least one of these set of checkboxes to be selected). If that's problematic, wondering why aria-required is allowed for checkbox.
I get in some situations, it's going to come down to scripting to make complex logic on groups of checkboxes work. I'm just trying to understand the approach taken so I can give the best guidance -- and maybe see the spec (whether aria or html) get tweaked to make it better.

@patrickhlauke
Copy link
Member

patrickhlauke commented Jul 16, 2021

ah sorry, somehow i completely misread your question / replaced it in my mind with radio buttons.

but fundamentally yes, the concept of "at least one checkbox in this group must be checked" doesn't seem to exist in HTML, and i'm not sure it's something that is exposed in a sensible/standardised way to the accessibility API.

@JAWS-test
Copy link

Because you ask here and not at ARIA, I give a WCAG answer (the ARIA answer would be: unfortunately not possible):

SC 1.3.1:

Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text

Since required cannot be transmitted programmatically, it must be in text form. I.e. a correct solution would be to use an asterisk (*) in the <legend> of the <fieldset>

@JAWS-test
Copy link

See whatwg/html#6868

@fstrr
Copy link
Contributor

fstrr commented May 10, 2024

This issue looks like it can be closed. If it needs to be re-opened, please do that and convert it to a Discussion.

@fstrr fstrr closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants