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

modal-accessibility

它能做什么

这项技能检查模态对话框是否具有正确的角色、标签和键盘行为。适用于希望弹窗人人可用的前端开发者。

适用场景

  • ✓当你请智能体检查弹窗或模态框的无障碍性的时候。
  • ✓当键盘用户在对话框中无法继续操作,或无法关闭它的时候。
  • ✓当你在构建新的对话框组件,并希望它遵循基本无障碍规则的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

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

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能