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

tabindex

它能做什么

这项技能检查网页中 tabindex 属性的使用方式。适用于希望页面能与键盘和屏幕阅读器良好配合的开发者和编辑。

适用场景

  • ✓当页面中有正值的 tabindex 数字,改变了正常的 Tab 顺序的时候。
  • ✓当自定义按钮或控件无法用 Tab 键访问的时候。
  • ✓当无障碍审查标记出焦点顺序问题的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“在我的网站上按 Tab 键时,焦点跳来跳去,顺序很奇怪。请帮我检查 tabindex 设置。”

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

工作原理

智能体会查找破坏自然顺序的 tabindex 值并加以修正。自定义控件会被设为 0,使键盘用户能够访问它们。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Use appropriate tabindex values

Incorrect tabindex values can create a confusing navigation experience, making it difficult for keyboard users to predict where focus will move next.

Quick Reference

  • Stick to tabindex="0" for custom interactive elements
  • Use tabindex="-1" for elements that should only be focusable via script
  • Avoid positive values (1, 2, 3...) which break natural tab order

Check

Check for any positive tabindex values and ensure custom interactive elements are focusable.

Fix

Remove positive tabindex values and use tabindex="0" or -1 appropriately.

Explain

Explain why positive tabindex values are problematic for keyboard navigation and user experience.

Code Review

Review the rendered markup and interactive states that affect Use appropriate tabindex values. 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/tabindex

常见问题

tabindex 为 0 有什么作用?

它使自定义元素可以通过 Tab 键访问,并按其在页面中的正常位置排列。

为什么正值的 tabindex 是个问题?

它们会把元素移到 Tab 顺序的最前面,使键盘用户难以预测页面的操作顺序。

应该先检查内置按钮和链接吗?

应该。这项技能指出,要先检查原生 HTML 元素,因为它们通常是更好的选择。

详情

作者的原始描述

Use when reviewing rendered HTML, interactive components, or design-system patterns related to Use appropriate tabindex values. 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
排名
#3044
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能