Communitygithub.com

SamuelChien/mega-skills-collection

Web 无障碍模式,符合 WCAG 2.2 标准,包括 ARIA、键盘导航、屏幕阅读器和测试。

mega-skills-collection 是什么?

该技能提供了全面的 Web 无障碍模式(Accessibility)最佳实践,旨在帮助开发者创建符合 WCAG 2.2 标准的网站和应用程序。它涵盖了语义化 HTML、ARIA 模式、键盘导航、表单无障碍、颜色对比度等关键领域,并提供了实用的代码示例(HTML、CSS、React TSX)和反模式警告。技能适用于所有现代前端框架(如 React)和原生 HTML/CSS 项目,帮助确保应用对使用键盘、屏幕阅读器(如 VoiceOver 和 NVDA)的用户无障碍。通过遵循其中的清单,开发者可以快速检查并修复常见的无障碍问题,最终提升产品的包容性和用户体验。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/SamuelChien/mega-skills-collection/tree/HEAD/accessibility-wcag

在你喜欢的 AI 中提问

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

文档

无障碍与 WCAG

语义化 HTML

<!-- 使用语义化元素代替通用 div -->
<header>
  <nav aria-label="主导航">
    <ul>
      <li><a href="/" aria-current="page">首页</a></li>
      <li><a href="/products">产品</a></li>
      <li><a href="/about">关于</a></li>
    </ul>
  </nav>
</header>

<main>
  <article>
    <h1>产品详情</h1>
    <section aria-labelledby="specs-heading">
      <h2 id="specs-heading">规格说明</h2>
      <dl>
        <dt>重量</dt>
        <dd>1.2 kg</dd>
        <dt>尺寸</dt>
        <dd>30 x 20 x 10 cm</dd>
      </dl>
    </section>
  </article>
</main>

<footer>
  <p>&copy; 2024 公司名称</p>
</footer>

使用 <nav>、<main>、<article>、<section>、<aside> 代替 <div> 作为地标。屏幕阅读器使用这些元素来导航页面。

ARIA 模式

function Modal({ isOpen, onClose, title, children }) {
  if (!isOpen) return null;

  return (
    <div
      role="dialog"
      aria-modal="true"
      aria-labelledby="modal-title"
      onKeyDown={(e) => e.key === "Escape" && onClose()}
    >
      <h2 id="modal-title">{title}</h2>
      <div>{children}</div>
      <button onClick={onClose} aria-label="关闭对话框">
        <XIcon aria-hidden="true" />
      </button>
    </div>
  );
}

function Tabs({ tabs, activeIndex, onChange }) {
  return (
    <div>
      <div role="tablist" aria-label="设置分区">
        {tabs.map((tab, i) => (
          <button
            key={tab.id}
            role="tab"
            id={`tab-${tab.id}`}
            aria-selected={i === activeIndex}
            aria-controls={`panel-${tab.id}`}
            tabIndex={i === activeIndex ? 0 : -1}
            onClick={() => onChange(i)}
            onKeyDown={(e) => handleArrowKeys(e, i, tabs.length, onChange)}
          >
            {tab.label}
          </button>
        ))}
      </div>
      {tabs.map((tab, i) => (
        <div
          key={tab.id}
          role="tabpanel"
          id={`panel-${tab.id}`}
          aria-labelledby={`tab-${tab.id}`}
          hidden={i !== activeIndex}
          tabIndex={0}
        >
          {tab.content}
        </div>
      ))}
    </div>
  );
}

键盘导航

function handleArrowKeys(
  event: React.KeyboardEvent,
  currentIndex: number,
  totalItems: number,
  onSelect: (index: number) => void
) {
  let newIndex = currentIndex;

  switch (event.key) {
    case "ArrowRight":
    case "ArrowDown":
      newIndex = (currentIndex + 1) % totalItems;
      break;
    case "ArrowLeft":
    case "ArrowUp":
      newIndex = (currentIndex - 1 + totalItems) % totalItems;
      break;
    case "Home":
      newIndex = 0;
      break;
    case "End":
      newIndex = totalItems - 1;
      break;
    default:
      return;
  }

  event.preventDefault();
  onSelect(newIndex);
}

所有可交互元素必须可通过键盘访问。Tab 键用于焦点导航,Enter/Space 键用于激活,方向键用于组件内部导航。

表单无障碍

function SignupForm() {
  return (
    <form aria-labelledby="form-title" noValidate>
      <h2 id="form-title">创建账户</h2>

      <div>
        <label htmlFor="email">电子邮件地址</label>
        <input
          id="email"
          type="email"
          required
          aria-required="true"
          aria-describedby="email-hint email-error"
          aria-invalid={hasError ? "true" : undefined}
        />
        <p id="email-hint">我们绝不会分享您的电子邮件。</p>
        {hasError && (
          <p id="email-error" role="alert">
            请输入有效的电子邮件地址。
          </p>
        )}
      </div>

      <button type="submit">创建账户</button>
    </form>
  );
}

颜色与对比度

:root {
  --text-primary: #1a1a1a;      /* 白色背景上对比度 15.3:1 */
  --text-secondary: #595959;    /* 白色背景上对比度 7.0:1 */
  --text-on-primary: #ffffff;   /* 确保品牌色背景上对比度 4.5:1 */
  --border-focus: #0066cc;      /* 可见的焦点环 */
}

*:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
}

.error-message {
  color: #d32f2f;
  /* 不要仅依赖颜色 - 需添加图标或文本前缀 */
}
.error-message::before {
  content: "错误: ";
  font-weight: bold;
}

WCAG AA 要求普通文本对比度不低于 4.5:1,大文本(18px 粗体或 24px 常规)不低于 3:1。

反模式

  • 使用 div 和 span 作为可点击元素,而不是 button 或 a
  • 移除焦点轮廓但未提供替代指示符
  • 仅依赖颜色传递信息(红色表示错误,绿色表示成功)
  • 在可见文本已标记元素时使用 aria-label
  • 自动播放媒体但没有暂停机制
  • 缺少供键盘用户使用的跳过导航链接

检查清单

  • 所有可交互元素均可通过键盘访问(Tab、Enter、Escape、方向键)
  • 使用了语义化 HTML 地标(nav、main、article、section)
  • 图片包含描述性的 alt 文本(装饰性图片使用 alt="")
  • 颜色对比度满足 WCAG AA 标准(普通文本 4.5:1,大文本 3:1)
  • 所有可交互元素上有可见的焦点指示符
  • 表单输入有关联的 <label> 元素
  • 错误消息通过 role="alert" 向屏幕阅读器播报
  • 页面已使用屏幕阅读器(VoiceOver、NVDA)和纯键盘进行测试

Individual skills in this repo

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

SamuelChien/mega-skills-collection

Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

SamuelChien/mega-skills-collection

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

SamuelChien/mega-skills-collection

Ingeniero de Sistemas de Andru.ia. Diseña, redacta y despliega nuevas habilidades (skills) dentro del repositorio siguiendo el Estándar de Diamante.

SamuelChien/mega-skills-collection

Estratega de Inteligencia de Dominio de Andru.ia. Analiza el nicho específico de un proyecto para inyectar conocimientos, regulaciones y estándares únicos del sector. Actívalo tras definir el nicho.

SamuelChien/mega-skills-collection

2D game development principles. Sprites, tilemaps, physics, camera.

SamuelChien/mega-skills-collection

3D game development principles. Rendering, shaders, physics, cameras.

SamuelChien/mega-skills-collection

Expert in building 3D experiences for the web - Three.js, React Three Fiber, Spline, WebGL, and interactive 3D scenes. Covers product configurators, 3D portfolios, immersive websites, and bringing depth to web experiences.

SamuelChien/mega-skills-collection

Accessibility audit skill for scanning, fixing, and verifying WCAG 2.2 Level A and AA compliance across React, Next.js, Vue, Angular, Svelte, and plain HTML codebases. Use when auditing accessibility, fixing a11y violations, checking color contrast, generating compliance reports, or integrating accessibility checks into CI/CD pipelines.

SamuelChien/mega-skills-collection

Ab Test Analyzer - Auto-activating skill for Data Analytics. Triggers on: ab test analyzer, ab test analyzer Part of the Data Analytics skill category.

SamuelChien/mega-skills-collection

A B Test Config Creator - Auto-activating skill for ML Deployment. Triggers on: a b test config creator, a b test config creator Part of the ML Deployment skill category.

SamuelChien/mega-skills-collection

When the user wants to plan, design, or implement an A/B test or experiment. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "conversion experiment," "statistical significance," or "test this." For tracking implementation, see analytics-tracking.

SamuelChien/mega-skills-collection

Acceptance Criteria Creator - Auto-activating skill for Enterprise Workflows. Triggers on: acceptance criteria creator, acceptance criteria creator Part of the Enterprise Workflows skill category.

SamuelChien/mega-skills-collection

Use when a coding task should be driven end-to-end from issue intake through implementation, review, deployment, and acceptance verification with minimal human re-intervention.

SamuelChien/mega-skills-collection

Accessibility Audit Runner - Auto-activating skill for Frontend Development. Triggers on: accessibility audit runner, accessibility audit runner Part of the Frontend Development skill category.

SamuelChien/mega-skills-collection

You are an accessibility expert specializing in WCAG compliance, inclusive design, and assistive technology compatibility. Conduct audits, identify barriers, and provide remediation guidance.

SamuelChien/mega-skills-collection

Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed, or change policy for the Discord channel.

SamuelChien/mega-skills-collection

Create unified specification packages across Business, Development, and Design teams. Staged elaboration (L0 Vision → L1 Requirements → L2 Team Detail → L3 Acceptance Criteria) to build shared understanding. Does not write code.

SamuelChien/mega-skills-collection

Research a company or person and get actionable sales intel. Works standalone with web search, supercharged when you connect enrichment tools or your CRM. Trigger with "research [company]", "look up [person]", "intel on [prospect]", "who is [name] at [company]", or "tell me about [company]".

SamuelChien/mega-skills-collection

Create forensically sound bit-for-bit disk images using dd and dcfldd while preserving evidence integrity through hash verification.

SamuelChien/mega-skills-collection

Validate messaging consistency across website, GitHub repos, and local documentation generating read-only discrepancy reports. Use when checking content alignment or finding mixed messaging. Trigger with phrases like "check consistency", "validate documentation", or "audit messaging".

相关技能