I am faced with a rather unique accessibility challenge. For reference, it is related to the way templates from Moodle's Database activity work but I will describe the limitations below.
I have three available templates in a list view of data: a header, a repeatable row template for each datum, and a footer (not relevant). I can use any HTML in a template but due to input filters block-level elements are closed at the end of each template. So I cannot, for instance, put the list view in a table (I would end up with N + 1 tables: one for the header and one for each datum row). I want a responsive list, where the header is not visible on a narrow screen while individual labels are visible in each repeated row.
The challenge is to semantically associate each label with its value. This thread was very useful but unless I missed something, it does not solve my problem. I cannot use aria-labelledby
or aria-describedby
in the rows because they use ID (which must be unique) references and I cannot generate unique IDs in each row (I do not have access to an index-like replacement in the templates, only raw values). <label>
is only for input elements but I believe even if I could use it here I'd still run into the ID challenge.
So basically I have:
<!-- header tpl -->
<div class="row header">
<span class="hidden-xs">Field One</span>
</div>
<!-- repeated row tpl -->
<div class="row data-row">
<span class="visible-xs hidden-sm label">Field One:</span>
<span class="value">[[field one value]]</span>
</div>
but cannot figure out how to semantically associate .label
with .value
. I looked at adding aria-label
on .value
but MDN says that is a "a string value that labels an interactive element" and this is a static list of data, not interactive. I also worry that the visual label plus aria-label
are redundant for screenreaders.
Maybe a semantic association isn't necessary and because of the text order it's fine? It seems like I should be able to do better, though.
`/`- `/`
- ` list would work. Semantically, that would be the right element, but unfortunately, screen readers do not treat definition lists the same. If you have 3 pairs of dt/dd elements, some screen readers will say you have a list with 3 items (which makes sense) but only allow you to navigate to the "term" elements using the screen reader `i` key. Other screen readers say the list has 6 items (not really correct) but at least you can navigate to each term and definition using the `i` key.
– slugolicious Apr 20 '23 at 22:26