aria-treeitem-name
它能做什么
这项技能检查树形小组件中的项目是否有清晰的名称和展开状态。适合构建文件浏览器、嵌套菜单或组织结构图的开发者。
适用场景
- ✓当你构建文件浏览器、嵌套导航或树形视图时。
- ✓当树形项目的名称为空或过于笼统,例如 folder 或 item 时。
- ✓当可展开的项目没有说明它是打开还是关闭时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/aria-treeitem-name/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的文件树里,文件夹只会被屏幕阅读器读成 item。请修正这些名称。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查每个树形项目的名称,依次使用 aria-labelledby、aria-label 和可见文字,并确认可展开的项目具有展开状态。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Provide accessible names for tree items
Tree widgets represent hierarchical data (file explorers, nested navigation, organization charts). Screen readers announce each focused treeitem's name, level, and position — e.g., 'src, collapsed, level 1, 1 of 3'. If the name is empty or generic ('folder', 'item'), blind users cannot distinguish between nodes and cannot navigate the hierarchy with confidence. VoiceOver on macOS uses the name to populate the rotor, and NVDA reads it as the user moves through the tree with arrow keys.
Quick Reference
- Every element with
role='treeitem'must have a non-empty accessible name - Text content of the element is used as the name by default — ensure it is descriptive
- Use
aria-labelto override or supplement the visible text (e.g., adding file type context) - Use
aria-labelledbyto compose a name from multiple visible elements within the item - A treeitem with
aria-expandedmust also convey its expanded/collapsed state — this is separate from its name
Check
Find all elements with role='treeitem'. For each, determine its accessible name via the accname computation: check aria-labelledby first, then aria-label, then visible text content. Flag any treeitem with an empty or whitespace-only accessible name. Also check whether treeitems with children have aria-expanded set to 'true' or 'false' (not just absent).
Fix
For each unnamed treeitem: (1) If the element has visible text content that is descriptive, no change is needed — the text content becomes the accessible name. (2) If the visible text is ambiguous (e.g., an icon with no text), add aria-label='Descriptive name'. (3) If the item has multiple text parts (e.g., filename + file size), use aria-labelledby referencing the most descriptive element's id. (4) For expandable treeitems, ensure aria-expanded='true' or aria-expanded='false' is present and toggled on expand/collapse.
Explain
WAI-ARIA 1.2 requires that treeitem elements have an accessible name as part of the tree widget pattern. Screen readers convey position within the tree using: name + level (aria-level or DOM nesting depth) + set size (aria-setsize) + position in set (aria-posinset) + expanded state (aria-expanded). The name is the only user-facing identifier — without it, a user navigating by arrow keys hears only 'treeitem, level 2' with no way to know which node they are on.
Code Review
Review the rendered markup and interactive states that affect Provide accessible names for tree items. Flag exact elements, roles, labels, focus behavior, or keyboard interactions that violate the rule, and note how to verify the fix with browser accessibility tooling or assistive tech.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/accessibility/aria-treeitem-name
常见问题
一个好的树形项目,屏幕阅读器会读出什么?
这项技能举例说明,例如 src、已折叠、第 1 级、第 1 项(共 3 项),其中包括名称、状态和位置。
屏幕阅读器首先使用哪个名称?
这项技能说明,先检查 aria-labelledby,然后是 aria-label,最后是可见的文字内容。
可展开的项目需要自己的状态吗?
需要。这项技能说明,带有子项的项目需要把 aria-expanded 设为 true 或 false。
详情
作者的原始描述
Use when applies to custom tree widgets built with role='tree', role='treeitem', and role='group'. Common in file explorers, nested navigation menus, org charts, and any UI where items can be expanded or collapsed to reveal children.
热度
- GitHub 星标
- 75k
- 排名
- #2741
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。