跳到正文
Skillpedia
网站与界面(前端)75k · #2735

aria-required-children

它能做什么

这项技能检查标签列表、菜单和树等复合小组件是否包含正确的子元素。适合用 div 和 span 构建自定义标签页、列表或菜单的开发者。

适用场景

  • ✓当你用 div 元素构建自定义标签组、菜单或列表框时。
  • ✓当屏幕阅读器没有读出列表或菜单中的项目数量时。
  • ✓当你用自定义列表、选择框或导航控件代替原生 HTML 时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/aria-required-children/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/aria-required-children/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的自定义标签栏使用的是普通 div。请确保标签项在标签列表中具有正确的角色。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会检查每个容器角色必须拥有的子角色,例如 tablist 中的 tab 或 list 中的 listitem,并在需要时为包装元素添加 presentation 角色。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Ensure ARIA roles contain required child roles

Screen readers like NVDA and VoiceOver navigate composite widgets (menus, tabs, trees) by moving between the required child roles. If a tablist contains <div> elements instead of role='tab', the user hears no tabs at all. JAWS announces 'list of 5 items' only when role='listitem' children exist inside role='list'. Without correct nesting, the entire widget becomes opaque to keyboard-only and screen reader users.

Quick Reference

  • Container roles mandate specific owned child roles: tablist → tab, list/listbox → listitem/option, menu/menubar → menuitem, tree → treeitem, grid/rowgroup → row
  • Missing required children break the accessibility tree so screen readers cannot enumerate items or announce counts
  • Use role='none' or role='presentation' on purely structural wrapper elements inside the container to avoid invalid nesting
  • Applies to WAI-ARIA 1.2 required owned elements for composite widget roles

Check

Identify all elements with ARIA container roles (tablist, list, listbox, menu, menubar, tree, treegrid, grid, rowgroup, radiogroup). For each, verify it contains the required owned child roles per the WAI-ARIA spec: tablist must own tab elements; list must own listitem; listbox must own option; menu/menubar must own menuitem, menuitemcheckbox, or menuitemradio; tree must own treeitem; grid must own row (which owns gridcell); radiogroup must own radio. Flag any container roles missing required children.

Fix

For each container role missing its required children: (1) Add the correct role to each child element — e.g., add role='tab' to each tab button inside role='tablist'. (2) If wrapper <div> elements exist between the container and the required children for layout purposes, add role='none' or role='presentation' to those wrappers. (3) Prefer native HTML equivalents where possible: <ul>/<li> instead of role='list'/role='listitem', <select>/<option> instead of role='listbox'/role='option'.

Explain

WAI-ARIA 1.2 defines 'required owned elements' for composite widget roles — these are the child roles a container must contain for the widget to be valid. Screen readers build their understanding of a widget from this structure. A tablist without tab children means a screen reader user in Forms Mode will find nothing to navigate between. A menu without menuitem children will not be announced as a menu at all in some ATs. This is distinct from aria-required-parent, which checks the inverse direction.

Code Review

Review the rendered markup and interactive states that affect Ensure ARIA roles contain required child roles. 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-required-children

常见问题

如果缺少子角色会怎样?

这项技能说明,屏幕阅读器可能不会读出项目或其数量,从而破坏导航。

role none 有什么作用?

它用于标记纯粹的结构性包装元素,使其不会破坏所需的结构。

它列举了哪些角色作为示例?

它提到了 tablist 中的 tab、list 中的 listitem、listbox 中的 option,以及 menu 中的 menuitem。

详情

作者的原始描述

Use when applies to custom ARIA widgets using composite roles: tablist, list, listbox, menu, menubar, tree, treegrid, grid, rowgroup, row, radiogroup. Use when reviewing components built with div/span elements that replace native HTML list, select, or nav elements.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2735
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能