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

focus-management

它能做什么

这项技能检查页面中的窗口打开、关闭或更新时,键盘焦点应该去往哪里。适用于构建模态框、菜单和单页应用的开发者。

适用场景

  • ✓当弹窗打开,但键盘焦点仍留在其后方的时候。
  • ✓当关闭对话框后,焦点停留在意外位置的时候。
  • ✓当单页应用切换视图,键盘用户迷失方向的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

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

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能