Closed aardrian closed 1 year ago
Move the
That's easy enough! Thanks for the suggestion!
Removing the
Now I'm wondering whether the question title ("Years of Experience", "Age", etc.) should be a label in the first place… Depending on the form input type, sometimes it's the <legend>
, but sometimes it's a <label>
for the input.
For example, comparing these two:
Here "Years of Experience" can be a legend, and we can reserve labels for "Less than one year", "1 to 2 years", etc.
But is it safe to do the same thing here? Is it ok to just not have a label at all for the number input?
<legend>
in a <fieldset>
, and the "How long..." could be a paragraph that is associated with the <fieldset>
via aria-describedby
(test that, though).<label>
for the text input, and the "How old..." would be a paragraph that is associated with the field via aria-describedby
.Is there any way to keep a consistent markup structure between the different question types? What if we added a hidden <label>
for the Age input?
Two questions, so two answers:
That being said if conditionally making the headings legends or labels based on the input type really is the best solution, I can implement it.
If you post pseudo-code of what you are thinking, that might help my mental model.
OK, then it sounds like the best solution would be having some kind of headingAsLabel={true}
prop on inputs that require it.
I appreciate the pseudo-code. That, sadly, is meaningless to me. I only speak HTML; all those fancy moon languages are lost on me. Probably years of moving from client to client where the only consistent language was HTML.
While the radio buttons live within a fieldset/legend construct, it is not being conveyed as expected because the construct is invalid HTML.
Using Firefox 117 with NVDA 2023.2, as I moved into each set of radio buttons I expected to hear the group label (anticipating it was the heading for the box). I did not.
This is the elided HTML showing the
<legend>
construct:A
<label>
and a<button>
nested in the<h3>
nested in the<legend>
is unnecessarily complex.<label>
uses thefor
attribute to map to anid
that does not exist on the page (try it://*[@id="html2023__features__datalist_element__experience"]
).<label>
did not resolve the issue, however.The fix, however, is straightforward. Move the
<legend>
to be a direct child of<fieldset>
. The intervening<div>
is breaking the association. The current construct is invalid HTML since<legend>
must be "the first child of a fieldset element" (see the WHATWG HTML spec).I have made a video to show this bug in action. As a screen reader user moves from one set of radios to the next, there is no context provided for what the radios are addressing. See it happen at 0:02 and 0:21.
https://github.com/Devographics/Monorepo/assets/1376607/0f9d58fa-2aaf-4c97-9ca7-23e1c024f57f