custom-element-accessibility
它能做什么
这项技能检查从零构建的自定义界面部件,例如特殊按钮或输入框。适合自行构建网页组件的开发者。
适用场景
- ✓当你从零构建了自定义按钮、菜单或输入框时。
- ✓当屏幕阅读器用户无法分辨自定义控件的作用时。
- ✓当自定义输入框在普通网页表单中无法正常工作时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/custom-element-accessibility/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能检查一下我的自定义小组件是否能用键盘和屏幕阅读器操作吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查小组件代码中缺失的 ARIA 标签、键盘处理和表单关联。然后建议添加内容,使小组件的行为与原生控件一致。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Make custom elements and Web Components accessible
Custom elements that lack ARIA reflection are invisible to screen readers — a button that looks correct visually may be announced as a generic "group" or not at all. ElementInternals provides the bridge between the shadow DOM and the accessibility tree, and it is also the only standards-compliant way to integrate custom inputs with native HTML forms.
Quick Reference
- Prefer native
<button>,<input>,<select>, and<details>before building a custom widget - Use ElementInternals.ariaRole to expose ARIA semantics from the shadow DOM
- Implement form-associated custom elements with ElementInternals for native form participation
- Apply roving tabindex for compound widgets (listbox, toolbar, menu)
- The shadow DOM does not automatically expose ARIA to the accessibility tree without ElementInternals
Check
Inspect these custom element definitions for missing ElementInternals setup, absent ARIA reflection, incomplete keyboard interaction patterns, and lack of form association for input-like components. First verify that the widget truly needs to be custom rather than a native control with styling.
Fix
Add ElementInternals attachment in the constructor, implement ariaRole and ariaLabel reflection, add keyboard event handlers following ARIA authoring patterns, and use formAssociated for custom input elements. Replace the component with native HTML when the native control already supports the required interaction.
Explain
Explain why the shadow DOM does not automatically expose ARIA semantics and how ElementInternals bridges the gap between custom elements and the accessibility tree.
Code Review
Review custom element class files for ElementInternals attachment, ARIA property reflection, keyboard interaction (Tab, Enter, Space, Arrow keys), focus management, and formAssociated static property on input-like elements. Flag cases where a native control would remove the accessibility burden entirely.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/html/custom-element-accessibility
常见问题
到底应该不应该构建自定义控件?
这项技能首先建议检查:带样式的标准 HTML 控件能否完成工作。自定义控件是最后的选择。
什么是 ElementInternals?
它是一项浏览器功能,使自定义组件能与页面共享其含义和表单数据。这项技能建议使用它。
它会检查小组件的哪些部分?
它会查看 ARIA 角色和标签、键盘交互,以及类似输入框部件的表单关联。
详情
作者的原始描述
Use when reviewing custom element class definitions or Web Component source code to check for missing ARIA reflection, keyboard handling, and form association.
热度
- GitHub 星标
- 75k
- 排名
- #2806
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。