Skip to content

Rule 2ee8b8 ("Visible label is part of accessible name"): introducing a new "label in name algorithm". #2075

Open
dan-tripp-siteimprove wants to merge 54 commits intoact-rules:developfrom
dan-tripp-siteimprove:rule-2ee8b8-may-2023
Open

Rule 2ee8b8 ("Visible label is part of accessible name"): introducing a new "label in name algorithm". #2075
dan-tripp-siteimprove wants to merge 54 commits intoact-rules:developfrom
dan-tripp-siteimprove:rule-2ee8b8-may-2023

Conversation

@dan-tripp-siteimprove
Copy link
Collaborator

@dan-tripp-siteimprove dan-tripp-siteimprove commented Jun 22, 2023

<< Describe the changes >>

Closes issue(s):

Need for Call for Review:
This will require a 2 weeks Call for Review


Pull Request Etiquette

When creating PR:

  • [ x] Make sure you're requesting to pull a branch (right side) to the develop branch (left side).
  • [x ] Make sure you do not remove the "How to Review and Approve" section in your pull request description

After creating PR:

  • [ x] Add yourself (and co-authors) as "Assignees" for PR.
  • [ x] Add label to indicate if it's a Rule, Definition or Chore.
  • [x ] Link the PR to any issue it solves. This will be done automatically by referencing the issue at the top of this comment in the indicated place.
  • [ x] Optionally request feedback from anyone in particular by assigning them as "Reviewers".

When merging a PR:

  • Close any issue that the PR resolves. This will happen automatically upon merging if the PR was correctly linked to the issue, e.g. by referencing the issue at the top of this comment.

How to Review And Approve

  • Go to the “Files changed” tab
  • Here you will have the option to leave comments on different lines.
  • Once the review is completed, find the “Review changes” button in the top right, select “Approve” (if you are really confident in the rule) or "Request changes" and click “Submit review”.
  • Make sure to also review the proposed Call for Review period. In case of disagreement, the longer period wins.

@dan-tripp-siteimprove dan-tripp-siteimprove added Rule Update Use this label for an existing rule that is being updated reviewers wanted labels Jun 22, 2023
@dan-tripp-siteimprove dan-tripp-siteimprove self-assigned this Jun 22, 2023
@dan-tripp-siteimprove dan-tripp-siteimprove changed the title Rule 2ee8b8 may 2023 Rule 2ee8b8 ("Visible label is part of accessible name"): introducing a new "label in name algorithm". Jun 22, 2023
@WilcoFiers
Copy link
Member

@dan-tripp-siteimprove Since this is being worked on still by @kengdoj, can we set this to draft?

@dan-tripp-siteimprove dan-tripp-siteimprove marked this pull request as draft July 20, 2023 21:19
@dan-tripp-siteimprove
Copy link
Collaborator Author

@dan-tripp-siteimprove Since this is being worked on still by @kengdoj, can we set this to draft?

Done

Jym77
Jym77 previously requested changes Nov 9, 2023
Copy link
Collaborator

@Jym77 Jym77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I like the details and the many new examples that explicit the decisions we've taken.


The <dfn id="for-text">visible inner text of a [text node][]</dfn> is:
- if the [text node][] is [visible][], its visible inner text is its [data][];
- if the [text node][] is not-[visible][], [rendered][], and contains only [whitespace][], its visible inner text is the string `" "` (a single ASCII whitespace);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional here sounds a bit weird 🤔
Notably, a text node that is not visible, rendered, and contains more than whitespace (e.g. in <span style="visibility: hidden">Hello</span>) would not trigger it and therefore have an empty string as visible inner text (rather than a whitespace).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting question. I don't know the answer. But I'll note that I copied this definition from sanshikan so if it needs fixing here, it probably needs fixing there too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, doing some archaeology, this is due to the fact that whitespace are not visible per our definition…

<button aria-label="hello world"><span>hello</span><span id="space"> </span><span>world</span></button>

The span#space is not visible (and neither is its child text node). So the first bullet doesn't apply. Without the second bullet, the visible inner text of the button would be helloworld, not matching the accessible name of hello world due to spacing…
I guess we need to add an example to show that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b2df021

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises another question: what should we do with this?
<a aria-label="Download specification" href="#"><span>Download</span><span style="visibility: hidden">x</span><span>specification</span></a>
According to the current definition, because of the clause "contains only [whitespace][]", the visible inner text of the <a> element is "Downloadspecification". Visually it looks like "Download specification". So I wonder if we could remove the clause "contains only [whitespace][]". What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 🤔 But if the span was invisible due to absolute positioning out of viewport, it shrould be removed:

<a aria-label="Download specification" href="#"><span>Download</span><span style="position: absolute; left: -9999px">x</span><span>specification</span></a>

I guess the true condition is whether it creates a CSS box that lies somewhere between the ones of the rest of the text taking part in the computation (and isn't fully contained in them), or something like that 🙈
Or maybe we just make the special case for visibility: hidden and assume that these is already a corner case and that it won't create too many true problems (We've been using that definition in Alfa for two years and I don't remember seeing a problem caused by it, so it may be safe to assume that it is a good enough approximation).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has given me a lot to think about. I'll try to bring it up in our next one-on-one meeting.

dan-tripp-siteimprove and others added 8 commits November 9, 2023 11:42
…://github.com/Siteimprove/sanshikan/blob/main/terms/visible-inner-text.md)

- changing glossary links' prefixes from "./" to "#".  I don't know if the former was working or not.  but the latter is the common practice, it seems.
Co-authored-by: Jean-Yves Moyen <jym@siteimprove.com>
Co-authored-by: Jean-Yves Moyen <jym@siteimprove.com>
…placing it with a new idea: the algorithm 'return value' eg. 'returns "is contained"'.

- rewording rule expectation.  I think that 'For the target element' is better than 'For each target element' because for this rule, the computation of the expecation for each applicable target element is done in isolation from the other applicable targets on the page.  It's simpler if the "for loop" over all applicable targets is done by the tool, not the rule.
@Jym77 Jym77 dismissed their stale review November 10, 2023 09:15

Changes done

#### Failed Example 5

This link has [visible][] text does not match the [accessible name][] because there are extra spaces in the accessible name.
This link has an [accessible name][] which contains a hyphen. The [label in name algorithm][] breaks up words on hyphens. So it turns "non-standard" into two tokens: "non" and "standard". So this fails the rule.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [label in name algorithm][] breaks up words on hyphens

That seems somewhat problematic, especially when considered from a speech input perspective, where aurally there is no meaningful difference between "non standard", "non-standard", and "nonstandard".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and it's unclear to me what the ideal fix for this would be, but I think this is a problem which - as I've said for other problems - "this PR didn't create, and didn't make worse" - am I right? If so, then I suggest - as I did with similar problems raised on this PR - that we deal with it later. In the spirit of incremental improvement.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the algorithm does make it worse by breaking a hyphenated word into two words. If the algorithm simply removed the hyphen (ignored it) rather than replacing it with a space, it would raise less false positives. I'm not saying it would be ideal, but less problematic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To address this I removed this Failed Example, in commit 1baf1ee


#### Failed Example 7

The rule has no special handling for abbreviations.
Copy link

@mbgower mbgower Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule has no special handling for abbreviations.

This seems problematic. For many abbreviations it is much more natural (in English) to say the full word when encountering an abbreviations (for example, abbreviations in an address like "Rd.", "St.", "Pl.", etc).

Perhaps it is just another shortcoming of this SC, but the calculation seems to me to need to be more fuzzy, and bias towards passing, not failing an abbreviation construct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I agree, but I consider this problem to be in the category of problems that this PR didn't create and didn't make worse. What do you think?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess two points.

The SC wording is: "the name contains the text that is presented visually."

We already have a rule stating that punctuation can be disregarded, so in this example, the displayed wording can be interpreted as "University Ave" and the name is "University Avenue". The accessible name literally contains the text that is presented visually (plus three more characters). So why is it a fail? It should be a pass, no?

The second point is just about abbreviations as synonyms. I can think of situations in English where it would be unusual to say only the abbreviation. For instance, if someone sees "Main St." or "First Rd.", they are going to say the abbreviation as the full word ("main street", "first road"). On the other hand "Ave" may be spoken as the full word or as the abbreviation. Part of me believes it is reasonable to compile a set of abbreviations which are commonly spoken as the full word, and not the abbreviation. But that seems unsustainable/unscalable.

On consideration, I reluctantly agree that failing a mismatch where the name does not contain all the characters of the displayed abbreviation (less punctuation) makes sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, if nothing else: here are some supporting arguments for failing abbreviations, from WCAG. These are independent of arguments about user impact. This is just about the letter of the law.

  1. "the exact string of the visible label does not occur in the accessible name" is mentioned as a reason for failure in failure technique F96 for this SC (https://www.w3.org/WAI/WCAG22/Techniques/failures/F96.html).
  2. "The accessible name contains a match for the string of the visible label" is a necessary condition for passing, under the "Procedure" section of - again - failure technique F96 for this SC.
  3. "When in doubt ... match the string exactly" - "Understanding SC 2.5.3: Label in Name" (https://www.w3.org/WAI/WCAG22/Understanding/label-in-name)

1 says "exact string" and 3 says "string exactly". That doesn't allow an abbreviation to pass.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's a good aspect to be thinking about, I don't agree that this is a problem for this test. From my experience (anecdotal of course) AT users want to have access to the same information as it is presented visually. In what cases would a non-sighted user need to have something fully spelled out and a sighted one wouldn't? While it's less severe of an impact, it's still impactful and should fail this test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point taken, but I've since side-stepped this by making anything with abbreviations inapplicable (inspired by per Giacomo's suggestion on Thursday). I did this in commit 9490a5e .

Co-authored-by: Mike Gower <gowerm@ca.ibm.com>
Copy link

@detlevhfischer detlevhfischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the computation of the label does not take into account cases where there is additional, clearly separated information following the label text that may be embedded in the same element, but should probably not be used when evaluating whether name contains the label string. Example:
<label>First name (required)</label><input type="text" aria-label="First name">

This would formally fail, but it probably shouldn't.

The broader problem is that the purpose of the SC (to allow predictable and workable speech input) is practically undone in cases where longish label text is included in the accessible name in order to meet 2.5.3. When using voice control on mobile phones, speaking the long label text to activate the element will then often not work. So, a formal PASS, but a practical FAIL.

Not sure how to include this in the algorithm though.

@dan-tripp-siteimprove
Copy link
Collaborator Author

I'd like to thank everyone for the comments in recent weeks. Unfortunately I have been too occupied with other work to respond to them. I hope to have time in late May.

@netlify
Copy link

netlify bot commented Jan 29, 2026

Deploy Preview for act-rules ready!

Name Link
🔨 Latest commit 8ea29b6
🔍 Latest deploy log https://app.netlify.com/projects/act-rules/deploys/698b27690fa0e80008464069
😎 Deploy Preview https://deploy-preview-2075--act-rules.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dan-tripp-siteimprove
Copy link
Collaborator Author

Example: <label>First name (required)</label><input type="text" aria-label="First name">

This would formally fail, but it probably shouldn't.

Actually, on further inspection, I believe that example would pass the rule (in the rule's current state in this PR), due to the step of the algorithm which removes round brackets and everything inside of them.

@detlevhfischer
Copy link

detlevhfischer commented Jan 29, 2026

I believe that example would pass the rule (in the rule's current state in this PR), due to the step of the algorithm which removes round brackets and everything inside of them.

Point taken. It still seems odd that (if I read the procedure correctly) First name (required) would pass, but not First name - required or First name | required or first name [required] whatever other variant authors would come up with.

… the assumptions to the applicability. as per meeting 2026-02-05.

 - adding clause to applicability: any widget that contains an image is inapplicable (due to lack of OCR in this rule - would cause a false positive.)
 - in some html examples: minor formatting fixes.
@dan-tripp-siteimprove dan-tripp-siteimprove requested review from dd8, kengdoj and shunguoy and removed request for dd8, kengdoj and shunguoy February 25, 2026 23:01
- The element has [visible text content][]; and
- The element has an `aria-label` or `aria-labelledby` attribute.
- The element does not contain any [rendered image resources][rendered image resource].
- If there are any words that appear in both the element's accessible name and its visible label, then for each such pair, the same spelling and hyphenation is used in both places.
Copy link
Collaborator

@kengdoj kengdoj Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear why this (line 41) is under Applicability. Maybe an Inapplicable Example would help.


#### Passed Example 14

This example passes the rule because "YYYY-MM-DD" is in brackets. Text in brackets is removed by the [label in name algorithm][], because it is not normally spoken by speech-input users.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since square or curly brackets aren't mentioned in the algorithm,

Suggested change
This example passes the rule because "YYYY-MM-DD" is in brackets. Text in brackets is removed by the [label in name algorithm][], because it is not normally spoken by speech-input users.
This example passes the rule because "YYYY-MM-DD" is in round brackets. Text in round brackets is removed by the [label in name algorithm][], because it is not normally spoken by speech-input users.


#### Failed Example 11

This rule has no special handling which tries to guess when number have the same semantic meaning. It operates on tokens only.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This rule has no special handling which tries to guess when number have the same semantic meaning. It operates on tokens only.
This rule has no special handling which tries to guess when numbers have the same semantic meaning. It operates on tokens only.


#### Failed Example 12

Similar to the previous example.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Similar to the previous example.
Similar to the previous example. This rule has no special handling which tries to guess when numbers have the same semantic meaning. It operates on tokens only.


#### Passed Example 8

Similar to the previous example.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe include additional description, like:

Suggested change
Similar to the previous example.
Similar to the previous example. The [label in name algorithm][] inserts whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Agenda item Rule Update Use this label for an existing rule that is being updated

Projects

None yet