autofocus-avoidance
它能做什么
这项技能检查页面加载时,焦点是否会意外地移动到某个表单字段上。适合构建表单位于其他内容下方的页面的开发者。
适用场景
- ✓当页面的某个带有 autofocus 的表单字段位于标题或引言文字下方时。
- ✓当屏幕阅读器用户反映自己被带到页面中间时。
- ✓当你审查使用 autofocus 的登录或搜索页面时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/autofocus-avoidance/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请移除我服务页面上联系表单的 autofocus,让屏幕阅读器用户从页面顶部开始。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会搜索表单元素上的 autofocus 属性并将其删除,或只在用户进行某个操作之后,才用 JavaScript 设置焦点。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Avoid autofocus on form fields
Autofocus teleports screen reader users to mid-page without context—they miss everything before the form and have no idea where they landed.
Quick Reference
- Avoid autofocus on pages with content before the form
- Autofocus disrupts screen reader users who lose page context
- Use JavaScript focus after user interaction instead of page load
- Login and search-only pages are exceptions where autofocus may be acceptable
Check
Search for autofocus attributes on form elements. Verify that page load does not unexpectedly move focus away from the page top, especially on pages with content before the form.
Fix
Remove autofocus attributes from form elements. If focus management is needed, use JavaScript to set focus after user interaction rather than automatically on page load.
Explain
Explain how autofocus moves screen reader users to mid-page without context, can trigger unexpected scrolling, and disrupts users who were reading content before the focused element.
Code Review
Review the rendered markup and interactive states that affect Avoid autofocus on form fields. 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/autofocus-avoidance
常见问题
为什么 autofocus 是个问题?
这项技能说明,屏幕阅读器用户会失去表单之前内容的上下文,也不知道自己被带到了哪里。
有没有适合使用 autofocus 的情况?
有。这项技能说明,仅有登录或仅有搜索的页面可以作为例外。
那应该如何设置焦点?
用 JavaScript,在用户与页面进行交互之后再设置。
详情
作者的原始描述
Use when reviewing rendered HTML, interactive components, or design-system patterns related to Avoid autofocus on form fields. Check native semantics first, then inspect keyboard behavior, focus flow, accessible names, and screen-reader output where relevant.
热度
- GitHub 星标
- 75k
- 排名
- #2750
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。