focus-management
它能做什么
这项技能检查页面中的窗口打开、关闭或更新时,键盘焦点应该去往哪里。适用于构建模态框、菜单和单页应用的开发者。
适用场景
- ✓当弹窗打开,但键盘焦点仍留在其后方的时候。
- ✓当关闭对话框后,焦点停留在意外位置的时候。
- ✓当单页应用切换视图,键盘用户迷失方向的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/focus-management/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请确保我的模态框打开和关闭时,键盘焦点都能正确移动。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查焦点在打开和关闭时如何移动,以及它是否保持在模态框之内。它会建议把焦点移入对话框、使其保持在其中,并在关闭时返回到触发按钮。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Manage focus during dynamic interactions
Poor focus management leaves keyboard users stranded—they can't find new content, get trapped in closed modals, or lose their place entirely after interactions.
Quick Reference
- Move focus to modal when opened, return to trigger when closed
- Focus new content after SPA navigation or dynamic updates
- Use tabindex='-1' to make non-interactive elements focusable
- Never lose focus to an unexpected location
Check
Verify that focus is properly managed when opening/closing modals, navigating between views, or updating content dynamically.
Fix
Implement proper focus management using tabindex, focus(), and focus trapping for modal dialogs.
Explain
Explain how proper focus management ensures keyboard and screen reader users can navigate dynamic interfaces effectively.
Code Review
Review the rendered markup and interactive states that affect Manage focus during dynamic interactions. 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/focus-management
常见问题
模态框打开时,焦点应去往哪里?
这项技能建议把焦点移入模态框,关闭模态框时再返回打开它的按钮。
什么是焦点陷阱?
它会让键盘焦点保持在对话框内,直到对话框关闭,使用户不会按 Tab 键进入隐藏的页面内容。
tabindex -1 有什么作用?
这项技能说明,它使非交互元素可以由代码获得焦点,而不会加入正常的 Tab 顺序。
详情
作者的原始描述
Use when reviewing rendered HTML, interactive components, or design-system patterns related to Manage focus during dynamic interactions. Check native semantics first, then inspect keyboard behavior, focus flow, accessible names, and screen-reader output where relevant.
热度
- GitHub 星标
- 75k
- 排名
- #2849
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。