modal-accessibility
它能做什么
这项技能检查模态对话框是否具有正确的角色、标签和键盘行为。适用于希望弹窗人人可用的前端开发者。
适用场景
- ✓当你请智能体检查弹窗或模态框的无障碍性的时候。
- ✓当键盘用户在对话框中无法继续操作,或无法关闭它的时候。
- ✓当你在构建新的对话框组件,并希望它遵循基本无障碍规则的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/modal-accessibility/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我检查弹窗,确保键盘用户可以打开、使用并关闭它们。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查对话框是否有正确的 ARIA 角色和标签,让 Tab 焦点保持在对话框内,用 Escape 键关闭,并将焦点返回到打开它的元素。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Make modal dialogs keyboard accessible
Without proper focus trapping and keyboard handling, modal dialogs are invisible traps for keyboard users—they can't navigate, can't escape, and can't complete tasks.
Quick Reference
- Use role='dialog' and aria-modal='true' on the modal container
- Trap focus inside the modal—Tab should cycle within modal only
- Close on Escape key press and return focus to trigger element
- Add aria-labelledby pointing to the modal title
Check
Verify modals have proper ARIA roles, focus trapping, keyboard dismissal (Escape), and return focus on close.
Fix
Implement accessible modals using role='dialog', aria-modal='true', focus trapping, and proper keyboard handling.
Explain
Explain the accessibility requirements for modal dialogs including focus management, ARIA attributes, and keyboard interaction.
Code Review
Review the rendered markup and interactive states that affect Make modal dialogs keyboard accessible. 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/modal-accessibility
常见问题
对话框应该使用什么角色?
这项技能建议在容器上使用 role 为 dialog,并将 aria-modal 设为 true。
关闭后为什么要还原焦点?
这样键盘用户可以从原来的位置继续操作,而不会失去在页面上的位置。
对话框需要标题吗?
需要。这项技能建议使用 aria-labelledby 指向模态框标题。
详情
作者的原始描述
Use when reviewing rendered HTML, interactive components, or design-system patterns related to Make modal dialogs keyboard accessible. Check native semantics first, then inspect keyboard behavior, focus flow, accessible names, and screen-reader output where relevant.
热度
- GitHub 星标
- 75k
- 排名
- #2942
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。