Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Unclear which legend element to be used as accessible name for fieldset #145
What is the legend subtree?
Similarly for figure/figcaption, table/caption.
Cases to consider:
Good question! In this context I think it would be the child of the element in question (a heading inside a legend element for example), where it is the content of the child element that becomes the accessible name for the grandparent.
Continuing with legend as an example...
If the legend element has no children, the text content of the legend becomes the accessible name for the fieldset. If there is no legend element inside the fieldset, the fieldset does not have an acessible name (unless it's been provided using ARIA).
If the legend element has multiple conforming children, the combined text content inside those children would become the accessible name for the fieldset. I haven't tested this extensively though (because it isn't a pattern seen in the wild beyond span elements AFAIK).
If there are multiple legend elements inside the fieldset, only the first is used as the accessible name for the fieldset.
I'm not sure about the shadow DOM boundary, but a brief experiment suggests that inserting an element with
Another quick experiment suggests that putting
How did you experiment?
I tested in Firefox and Chrome on macOS, using their accessibility tree view in developer tools, with this test case.
In both browsers, the fieldset is represented as a "group" node with accessible name "The legend" for the first fieldset, and a "group" node with accessible name "" for the second fieldset, which suggests that there is a difference.
The spec doesn't say so AFAICT, and at least in Firefox, for this test case
the "group" node still has the accessible name "The legend". (In Chrome it is "".)
referenced this issue
Aug 28, 2018
For this test
Both Firefox and Chrome have empty accessible name for the "group" node in the accessibility tree.
Based on the above, I propose that the accessible name algorithm use the same logic as how it's defined semantically in the HTML standard:
Separately, on the difference for
Edge seems to not give the fieldset an accessible name at all, unless you use