w3c / accname

Accessible Name and Description Computation
https://w3c.github.io/accname/
61 stars 23 forks source link

Should the Host Language Label be used if it's empty? #234

Open dandclark opened 6 months ago

dandclark commented 6 months ago

The Host Language Label step E of the accname computation algorithm is unclear on whether the empty string should be used if that's what the native markup provides.

E. Host Language Label: Otherwise, if the current node's native markup provides an attribute (e.g. alt) or element (e.g. HTML label or SVG title) that defines a text alternative, return that alternative in the form of a flat string as defined by the host language, unless the element is marked as presentational (role="presentation" or role="none").

Going by a strict reading of the spec, I'd guess that an empty string should be used. However the img with tooltip label with empty alt subtest of accname/name/comp_tooltip.html suggests that an empty alt attribute should be ignored. Gecko and WebKit pass this test, while Blink fails.

If that test reflects the intended behavior, should the spec be updated to something like this?

E. Host Language Label: Otherwise, if the current node's native markup provides an attribute (e.g. alt) or element (e.g. HTML label or SVG title) that defines a text alternative, return that alternative in the form of a flat string as defined by the host language, unless the text alternative is an empty string or the element is marked as presentational (role="presentation" or role="none").

Also -- if the empty string is omitted, what about a whitespace-only string? (See https://github.com/w3c/accname/issues/233).

scottaohara commented 6 months ago

related https://github.com/w3c/html-aam/pull/533

aleventhal commented 6 months ago

Not that it answers this question, but I wanted to note that <img alt=""> is special. It historically was a way to indicate decorative/redundant images before ARIA existed. The presence of an alt attribute with the empty string tells screen readers like JAWS to not attempt to repair the missing alt attribute. We can't really break that since it's baked into the web at this point. But whether aria-label[ledby] should override that is another question.

MelSumner commented 2 months ago

The test reflects the desired behavior but alt="" is special TBH.

I have long been of the opinion that, since modern IDEs will pre-fill <img src="" alt=""/> for you, it should be permissible/valid to also add role="none" or role="presentation" to an image.

I do not think the specification should change here. If anything, we could add a note that this is a special case.