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

aria-hidden-focus

它能做什么

这项技能检查位于隐藏容器内的可聚焦元素。适合隐藏面板或菜单、并需要键盘焦点正确运作的开发者。

适用场景

  • ✓当面板用 aria-hidden 隐藏,但其中的链接或按钮仍可通过 Tab 键访问时。
  • ✓当键盘用户反映焦点消失在空处时。
  • ✓当你审查折叠或移出屏幕的内容时。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“我的侧边菜单用 aria-hidden 隐藏了,但人们仍然可以用 Tab 键进入。请修复这个问题。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会找出 aria-hidden 容器内的可聚焦子元素,并把它们的 tabindex 设为 -1,或使用 inert 属性阻止其获得焦点。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Remove focusable elements from aria-hidden containers

When a keyboard user tabs into an aria-hidden element, the screen reader remains silent, leaving the user with no idea where their focus is or what they can interact with.

Quick Reference

  • Elements with aria-hidden="true" must not contain focusable children
  • Focusing on a hidden element creates a 'ghost' focus for screen reader users
  • Use tabindex="-1" or inert to properly hide interactive elements

Check

Scan aria-hidden="true" containers for focusable elements like links, buttons, or inputs.

Fix

Add tabindex="-1" to focusable children inside aria-hidden containers or use the inert attribute.

Explain

Explain why focusable elements inside aria-hidden containers cause confusion for keyboard and screen reader users.

Code Review

Review the rendered markup and interactive states that affect Remove focusable elements from aria-hidden containers. 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/aria-hidden-focus

常见问题

焦点落在隐藏元素内会出现什么问题?

这项技能说明,屏幕阅读器用户听不到任何内容,因而不知道自己身在何处。

什么是 inert 属性?

它是一个 HTML 属性,可以让某个区域无法获得键盘焦点,这项技能把它作为一种选择提供。

这项技能列出了哪些修复方法?

它列出了将 tabindex 设为 -1,以及使用 inert 属性,作为隐藏交互元素的两种方式。

详情

作者的原始描述

Use when reviewing rendered HTML, interactive components, or design-system patterns related to Remove focusable elements from aria-hidden containers. 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
排名
#2728
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能