axe-core: False Positive: Form element has multiple
IMO this rule should be retired completely. Multiple labels for a form field are allowed by spec and work in most useragents. I believe it is only IE where they do not. This would be the simplest way to resolve.
However, even if it were to be kept the following should certainly not throw an error https://codepen.io/anon/pen/MrLgKm
<input type="checkbox" id="A" aria-labelledby="B">
<label class="indicator" aria-hidden="true" for="A">X</label>
<label for="A" id="B" class="ps-label">Yes/No Value</label>
Here there are 2 labels for the checkbox (the first is actually a CSS image in the real thing - but here I have added X for simplicity). They are both labels in order to increase the hit area for the checkbox. The first is hidden from screen readers with aria-hidden as it is not meaningful.
Even the addition of aria-labelledby on the checkbox which should override the labels does not seem to remove the aXe error.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 24 (18 by maintainers)
I am re-opening this because the
aria-labelledby
is overriding the other labels. This is a case we need to support.We need to decide how to handle this case:
I have tested on VO and it works correctly but we need more evidence that this is intended and fully implemented behavior
After talking with @AutoSponge and @WilcoFiers, and running extensive tests (https://codepen.io/straker/full/PvqONy), this is what we’ve come up with:
aria-labelledby
that points to hidden labels is consistently supported.aria-labelledby
that points to multiple visible labels is not quite supported. VoiceOver on iOS fails to read all labels.Taking that all into account, I propose we update the rule to:
aria-labelledby
is present due to iOS Safari)aria-hidden
(ifaria-labelledby
is not present due to Talkback)aria-labelledby
is present (doesn’t matter if hidden viaaria-hidden
or CSS)