I have a web app that displays and passes around user-editable semantic markup. For a variety of reasons, including security, the markup consists entirely of custom elements (plus the i
, b
, and u
tags). For regular rendering, I simply have styles for all the tags and stick them straight in the DOM. This looks and works great.
Now I’m doing screen-reader testing, and things aren’t great. I have a bunch of graphical symbols I want to add labels for. I’ve got divs that I want to make into landmarks. I’ve got custom input fields and buttons.
It would be easy enough to just add role=
to all the different tag instances. But part of the reason for the custom markup is to eliminate all the redundant information from the strings that get passed around (note: they’re also compressed). My <ns-math>
tag should always have role="math"
, and adding 11 bytes to what might be tags around a single character is an actual problem when multiplied out over a whole article. I know this because the app started with a bunch of <span class="...
type elements instead of custom.
For the fields and buttons, I’ve used a shadow DOM approach. This was necessary anyway to get focus/keyboard semantics correct without polluting the semantic markup with a bunch of redundant attributes, so it’s easy to also slap the ARIA stuff on the shadow elements. Especially since the inputs are all leaf nodes. But most of my custom tags amount to fancy span
s, and are mostly not leaf nodes, so I don’t really want to shadow them all when they’re working so well in the light DOM.
After a bunch of searching, it seems like the internals.role
property from “4.13.7.4 Accessibility semantics” of the HTML standard is maybe what I want. I may well be using it incorrectly (I’m a novice at front-end), but I can’t seem to get this to work in recent versions of Firefox or Chrome. I don’t get an error, but it seems to have no effect on the accessibility tree. My elements are not form-associated, but my reading is that the ARIAMixin
should be functional anyway. This is maybe a working draft? If this is supposed to work in current browsers, does anybody have a code snippet or example?
Is there some other straight-forward way to achieve my goal of accessibility-annotating my custom elements without adding a bunch of explicit attributes to the element instances?