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

aria-input-field-name

它能做什么

这项技能检查文本框、多行文本框和下拉菜单是否有正确的标签。适合构建表单、并希望每个人都知道每个字段用途的开发者。

适用场景

  • ✓当你用文本输入框、多行文本框或选择菜单构建表单时。
  • ✓当某个字段只有占位文字,没有标签时。
  • ✓当你在审查表单是否适合语音控制或屏幕阅读器使用时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/aria-input-field-name/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请检查我的结账表单,确保每个字段都有正确关联的标签。”

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

工作原理

智能体会查找通过 id 关联的 label 元素,或每个字段上的 aria-label、aria-labelledby,并标出仅依赖占位文字的字段。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Ensure all input fields have accessible names

Screen readers announce the accessible name of a focused input before the user types. Without a name, VoiceOver reads 'text field' and NVDA reads 'edit' with no context, making it impossible for blind users to fill out forms correctly. Voice control users (Dragon NaturallySpeaking) also need the visible label text to match the accessible name so they can say 'click Email Address' to move focus to the field.

Quick Reference

  • Every <input>, <textarea>, and <select> must have a programmatically associated accessible name
  • Preferred: associate a <label> via matching for/id attributes
  • Alternatives: aria-label (inline string) or aria-labelledby (references another element's id)
  • Placeholder text is not an accessible name — it disappears on input and is not reliably announced
  • Applies to WCAG 2.1 SC 1.3.1 (Info and Relationships) and SC 4.1.2 (Name, Role, Value)

Check

Find all <input> (excluding type='hidden'), <textarea>, and <select> elements. For each, check that one of these is true: (1) a <label> element with a for attribute matching the input's id exists, (2) the input has a non-empty aria-label attribute, or (3) the input has an aria-labelledby attribute pointing to a visible element. Flag any that use only placeholder as their label. Also check custom widgets using role=textbox, role=combobox, etc.

Fix

For each unlabeled input: (1) Add a <label for='input-id'>Label text</label> and matching id on the input — this is the most robust method. (2) If a visible label is impractical (e.g., search bar), add aria-label='Search' directly on the input. (3) If the label text already exists elsewhere in the DOM, add aria-labelledby='label-element-id' to the input. Remove placeholder as a substitute for a label; keep placeholder only as a hint for expected format.

Explain

WCAG 2.1 SC 4.1.2 (Name, Role, Value) requires that all user interface components have an accessible name. For form inputs, the accessible name is computed from: (1) aria-labelledby → (2) aria-label → (3) associated <label> → (4) title attribute (last resort). Screen readers announce this name when the input receives focus. Without it, a blind user hears only the input type ('text field') with no indication of what to type. Dragon NaturallySpeaking users need the accessible name to match visible text so voice commands work.

Code Review

Review the rendered markup and interactive states that affect Ensure all input fields have accessible names. 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-input-field-name

常见问题

为什么占位文字不够?

这项技能说明,占位文字在用户输入时就会消失,而且不能被可靠地读出。

给字段添加标签的首选方式是什么?

使用 label 元素,并通过匹配的 for 和 id 属性相连。

语音控制用户也需要标签吗?

需要。这项技能指出,语音控制用户通过说出可见的标签文字来找到字段。

详情

作者的原始描述

Use when applies to all `<input>` (except type=hidden), `<textarea>`, `<select>`, and custom form widgets using role=textbox, role=combobox, role=spinbutton, role=searchbox, or role=listbox.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能