Skip to content

fix: exclude group/menu descendants from treeitem/menuitem name-from-content - #1101

Open
ArmandRedgate wants to merge 1 commit into
eps1lon:mainfrom
ArmandRedgate:fix/treeitem-menuitem-name-from-content-exclusions
Open

ArmandRedgate wants to merge 1 commit into
eps1lon:mainfrom
ArmandRedgate:fix/treeitem-menuitem-name-from-content-exclusions

Conversation

@ArmandRedgate

@ArmandRedgate ArmandRedgate commented Aug 14, 2026 •

Copy link
Copy Markdown

Created with help from Claude (I am not familiar with this codebase, I will admit). Code seems reasonable on self-review and existing and new tests pass.

Summary

Fixes #1100.

Per the WAI-ARIA APG:

When calculating a name from content for the treeitem role, descendant content of child group elements are not included [...] a menuitem role with a menu descendant [...] is a similar case.

computeMiscTextAlternative previously recursed into every child node unconditionally when computing name-from-content, so an expanded treeitem's accessible name incorrectly concatenated the labels of its nested treeitem children (and similarly for menuitem/menu). Real browsers (confirmed via Chrome DevTools' accessibility tree) correctly exclude these descendants - this brings the computation in line with both the spec note and observed browser behavior.

Changes

  • sources/accessible-name-and-description.ts: added isExcludedFromNameFromContent, applied as a filter over childNodes in computeMiscTextAlternative before recursing.
  • sources/__tests__/accessible-name.js: added coverage for the treeitem/group case (using the spec's own Fruits/Apples/Bananas/Oranges example), the analogous menuitem/menu case, and a control case confirming an unrelated role (button) with a group descendant is unaffected.
  • .changeset/tricky-buttons-fly.md: changeset entry.

Test plan

  • yarn test - all 777 tests pass (768 existing + 9 new, across jsdom/mock-edge14/mock-ie11 projects)
  • yarn test:types - passes
  • yarn lint - passes

…content

Per the WAI-ARIA APG (https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/#naming_with_child_content):

"When calculating a name from content for the treeitem role, descendant
content of child group elements are not included [...] a menuitem role
with a menu descendant [...] is a similar case."

computeMiscTextAlternative previously recursed into every child node
unconditionally, so an expanded treeitem's accessible name incorrectly
concatenated the labels of its nested treeitem children (and similarly
for menuitem/menu). Real browsers correctly exclude these descendants;
this brings the library's computation in line with both the spec and
observed browser behavior.

Fixes eps1lon#1100

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent Tree Item accessible name behaviour

1 participant