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

autofocus-avoidance

它能做什么

这项技能检查页面加载时,焦点是否会意外地移动到某个表单字段上。适合构建表单位于其他内容下方的页面的开发者。

适用场景

  • ✓当页面的某个带有 autofocus 的表单字段位于标题或引言文字下方时。
  • ✓当屏幕阅读器用户反映自己被带到页面中间时。
  • ✓当你审查使用 autofocus 的登录或搜索页面时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/autofocus-avoidance/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

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

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能