Communitygithub.com

无障碍 (WCAG 2.2)

使用 WCAG 2.2 Level AA 标准设计、实现和审核包容性数字产品。在构建或审核必须满足 WCAG 2.2 Level AA 的用户界面,或审查键盘、对比度、屏幕阅读器支持变更时使用。

无障碍 (WCAG 2.2) 是什么?

该技能确保面向所有用户的数字界面具有可感知性、可操作性、可理解性和鲁棒性(POUR),包括使用屏幕阅读器、开关控制或键盘导航的用户。它专注于 WCAG 2.2 成功标准的技术实现,涵盖 Web、iOS 和 Android 平台。技能详细描述了如何识别组件角色、定义可感知属性、实现可操作控件、确保可理解逻辑以及验证鲁棒兼容性。同时提供了跨平台无障碍属性映射表、具体代码示例(包括 HTML、SwiftUI 和 Kotlin Compose)以及常见反模式和最佳实践清单,帮助开发者系统性地构建无障碍的数字产品。

兼容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/accessibility

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

无障碍 (WCAG 2.2) 是做什么的?

本技能确保数字界面对于所有用户(包括使用屏幕阅读器、开关控制或键盘导航的用户)具有可感知性、可操作性、可理解性和鲁棒性(POUR)。它专注于 WCAG 2.2 成功标准的技术实现。

使用时机

  • 定义 Web、iOS 或 Android 的 UI 组件规范。
  • 审核现有代码中的无障碍障碍或合规性差距。
  • 实现新的 WCAG 2.2 标准,如目标尺寸(最小)和焦点外观。
  • 将高级设计需求映射到技术属性(ARIA 角色、特性、提示)。

核心概念

  • POUR 原则:WCAG 的基础(可感知、可操作、可理解、鲁棒)。
  • 语义映射:使用原生元素而非通用容器,以提供内置无障碍支持。
  • 无障碍树:辅助技术实际“读取”的 UI 表示。
  • 焦点管理:控制键盘/屏幕阅读器光标的顺序和可见性。
  • 标签与提示:通过 aria-label、accessibilityLabel 和 contentDescription 提供上下文。

工作原理

第一步:识别组件角色

确定功能用途(例如:这是按钮、链接还是标签页?)。在诉诸自定义角色之前,优先使用最语义化的原生元素。

第二步:定义可感知属性

  • 确保文本对比度达到 4.5:1(正常文本)或 3:1(大文本/UI 组件)。
  • 为非文本内容(图片、图标)添加文本替代。
  • 实现响应式重排(缩放到 400% 时不丢失功能)。

第三步:实现可操作控件

  • 确保最小 24x24 CSS 像素 的触控目标尺寸(WCAG 2.2 SC 2.5.8)。
  • 验证所有交互元素可通过键盘访问,并具有可见的焦点指示器(SC 2.4.11)。
  • 为拖拽操作提供单指针替代方案。

第四步:确保可理解逻辑

  • 使用一致的导航模式。
  • 提供描述性的错误消息和更正建议(SC 3.3.3)。
  • 实现“冗余输入”(SC 3.3.7),避免重复询问相同数据。

第五步:验证鲁棒兼容性

  • 使用正确的 名称、角色、值 模式。
  • 为动态状态更新实现 aria-live 或活动区域。

无障碍架构图

flowchart TD
  UI["UI 组件"] --> Platform{平台?}
  Platform -->|网页| ARIA["WAI-ARIA + HTML5"]
  Platform -->|iOS| SwiftUI["无障碍特性 + 标签"]
  Platform -->|安卓| Compose["语义 + 内容描述"]

  ARIA --> AT["辅助技术(屏幕阅读器、开关)"]
  SwiftUI --> AT
  Compose --> AT

跨平台映射

功能网页 (HTML/ARIA)iOS (SwiftUI)安卓 (Compose)
主要标签aria-label / <label>.accessibilityLabel()contentDescription
次要提示aria-describedby.accessibilityHint()Modifier.semantics { stateDescription = ... }
动作角色role="button".accessibilityAddTraits(.isButton)Modifier.semantics { role = Role.Button }
实时更新aria-live="polite".accessibilityLiveRegion(.polite)Modifier.semantics { liveRegion = LiveRegionMode.Polite }

示例

网页:无障碍搜索

<form role="search">
  <label for="search-input" class="sr-only">搜索产品</label>
  <input type="search" id="search-input" placeholder="搜索..." />
  <button type="submit" aria-label="提交搜索">
    <svg aria-hidden="true">...</svg>
  </button>
</form>

iOS:无障碍操作按钮

Button(action: deleteItem) {
    Image(systemName: "trash")
}
.accessibilityLabel("删除项目")
.accessibilityHint("从列表中永久删除此项目")
.accessibilityAddTraits(.isButton)

安卓:无障碍开关

Switch(
    checked = isEnabled,
    onCheckedChange = { onToggle() },
    modifier = Modifier.semantics {
        contentDescription = "启用通知"
    }
)

应避免的反模式

  • Div-按钮:使用 <div> 或 <span> 处理点击事件,但未添加角色和键盘支持。
  • 仅靠颜色传达含义:仅通过颜色变化(例如将边框变红)来指示错误或状态。
  • 模态框焦点未受限:模态框未能限制焦点,导致键盘用户在模态框打开时可以导航到背景内容。焦点必须被包含在模态框内,并且可以通过 Escape 键或显式的关闭按钮退出(WCAG SC 2.1.2)。
  • 冗余替代文本:在替代文本中使用“...的图片”或“...的图像”(屏幕阅读器已经宣布“图像”角色)。

最佳实践检查清单

  • 交互元素满足 24x24px(网页)或 44x44pt(原生)的目标尺寸。
  • 焦点指示器清晰可见且高对比度。
  • 模态框在打开时 包含焦点,并在关闭时干净地释放焦点(Escape 键或关闭按钮)。
  • 下拉菜单和弹出框在关闭时将焦点恢复到触发元素。
  • 表单提供基于文本的错误建议。
  • 所有仅图标的按钮都有描述性文本标签。
  • 文本缩放时内容能正确重排。

参考

相关技能

  • frontend-patterns
  • design-system
  • liquid-glass-design
  • swiftui-patterns

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

相关技能