Repository navigation
Conversation
| } | ||
|
|
||
| #[test] | ||
| fn ignores_label_element_which_is_hidden() -> TestResult<()> { |
There was a problem hiding this comment.
I think this test and behavior is the inverse of what it should be. label is an example explicitly called out as something that shouldn't be ignored.
There was a problem hiding this comment.
Reading the spec makes my head hurt, but here goes:
If the current node is hidden and is:
- Not ...irrelevant to this test...
- Nor part of a native host language text alternative element (e.g. label in HTML) or attribute traversal, where the root of that traversal was hidden.
Return the empty string.
How one interprets this depends on how one should read "the root of that traversal". This test interprets that to be the button, which is not hidden. Which means that the current node (in this case, the label) is indeed not part of "a native host language text alternative where the root element of the traversal was hidden." The first criterion relates to attributes which don't appear in the code, so that clearly doesn't apply. Thus neither of the two criteria in the bullet points apply, so one reaches the conclusion "Return the empty string".
A test with Chromium indicates that it also follow this interpretation.
All very confusing, but I think this is correct.
16e1da7 to
6102224
Compare
This is requires to support setting the ARIA accessible name of an element through the _host language text_ of an element, especially an associated `<label>` element. This also adds support for setting the label through other forms of the host language text: - The `alt` text of an `<img>` tag. This is needed both for dioxus-test and to allow assistive technologies to correctly name many elements.
8fbaa61 to
e84a9f5
Compare
The existing implementation for setting the
labelandlabelled_byfields in accesskit nodes focused on thearia-labelandaria-labelledbyattributes. This adds support for the<label>element as well as thealtattribute of the<img>tag. This fills out support for the host language label as defined in the W3C ARIA spec.This adds suitable unit tests to ensure that the accesskit tree is correctly constructed.
There are still some gaps, such as support for the HTML global
titleattribute via accesskit'stooltipfield, but this brings the implementation much closer.One tradeoff for consideration: This implementation sets the
labelfield in each accesskitNodebased not just on the label, but thelabelledbyreferences as well. This means that all of the complicated logic surrounding how to put labels together is handled right when building the ARIA tree, and consumers can get the accessible name of an element by just callinglabel(). But this implies more memory use and slightly higher overhead than would be the case if the accesskit contract were minimally followed.Note for review: The production code in this PR is largely superseded by #1346. So this is interesting mostly for the test coverage it provides and the general question about using the accesskit label to store the computed accessible name.
Here are some measurements on the CPU and memory impact:
Setup
support-html-label-for-accessible-nameat commit8fbaa6162.SKIP_DERIVED_LABELSdisabled two things:aria-labelledbyand<label>targetssubtree_text)aria-labeland host-language labels (alt, inputvalue,figcaption, …) were still computed in both runs.blitz-domcompiled atopt-level = 3(--config profile.test.package.blitz-dom.opt-level=3). Other crates use the default test profile. Release flags were not used for the whole workspace.Instantaround 20 calls tobuild_accessibility_treeafter one warm-up call, averaged per call. Four separate process runs for each configuration.Test document (one synthetic page)
<button>Button number N</button><a href="#">Link number N with some longer link text</a><h2>Heading number N describing a section</h2><div role="button" aria-labelledby="lN">+<span id="lN"><label for="iN">+<input id="iN"><div><p>of plain paragraph textResulting tree: 33,004 accessibility nodes, of which 13,200 are
TextRunnodes.Results
labelbuild_accessibility_tree, 4 runsBox<str>allocations whose overhead I did not measure.For scale:
size_of::<accesskit::Node>()TextRunvalue text (13,200 nodes)The label text is about 4% of the sum of these three, excluding allocator overhead and child lists, which I did not measure.
Caveats
blitz-domwas optimised, and timings are wall-clock on a laptop.accesskit_consumerkeeps its copy while the window exists.What
accesskit_consumer0.39.1 would derive withoutlabel(from reading the source, not measured)labelled_bytargets are read only from the target'slabelproperty, orvaluefor aRole::Label. A generic target such as aspanhas no label and would contribute nothing.Button,CheckBox,DefaultButton,Link,MenuItem,MenuItemCheckBox,MenuItemRadioandRadioButton. Other roles (headings, cells, tabs, tree items) would have no name.Sa<b>ve</b>would giveSa ve.WPT results
No changes in test results compared to
main.Generated by the WPT workflow.