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

custom-element-accessibility

它能做什么

这项技能检查从零构建的自定义界面部件,例如特殊按钮或输入框。适合自行构建网页组件的开发者。

适用场景

  • ✓当你从零构建了自定义按钮、菜单或输入框时。
  • ✓当屏幕阅读器用户无法分辨自定义控件的作用时。
  • ✓当自定义输入框在普通网页表单中无法正常工作时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/custom-element-accessibility/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能