mcpField
A
accessibility-wcag

accessibility-wcag

github.com/rohitg00デザイン・UI2.8k225 回インストール24 週間前に更新
リポジトリ

accessibility-wcag について

フロントエンド開発者向けのWCAGアクセシビリティスキルです。セマンティックHTML、ARIA、フォーム、キーボード操作の確認項目をまとめています。

主な機能

  1. 01セマンティックHTMLのランドマーク
  2. 02ARIAの操作パターン
  3. 03キーボード対応の確認
  4. 04フォームのアクセシビリティ確認
  5. 05スクリーンリーダーのテスト指針

活用シーン

  1. 01ページのナビゲーション構造の確認
  2. 02モーダルのキーボード操作の改善
  3. 03フォームラベルとエラー通知の監査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/rohitg00/awesome-claude-code-toolkit --skill accessibility-wcag

インストール後、Claude Code で/accessibility-wcagを入力して読み込まれたか確認します。

詳細

アクセシビリティとWCAG

セマンティックHTML


<header>
  <nav aria-label="Main navigation">
    <ul>
      <li><a href="/" aria-current="page">Home</a></li>
      <li><a href="/products">Products</a></li>
      <li><a href="/about">About</a></li>
    </ul>
  </nav>
</header>

<main>
  <article>
    <h1>Product Details</h1>
    <section aria-labelledby="specs-heading">
      <h2 id="specs-heading">Specifications</h2>
      <dl>
        <dt>Weight</dt>
        <dd>1.2 kg</dd>
        <dt>Dimensions</dt>
        <dd>30 x 20 x 10 cm</dd>
      </dl>
    </section>
  </article>
</main>

<footer>
  <p>&copy; 2024 Company Name</p>
</footer>

ランドマークには<div>ではなく<nav>、<main>、<article>、<section>、<aside>を使用します。スクリーンリーダーはこれらを使ってページ内を移動します。

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="Close dialog">
        <XIcon aria-hidden="true" />
      </button>
    </div>
  );
}

function Tabs({ tabs, activeIndex, onChange }) {
  return (
    <div>
      <div role="tablist" aria-label="Settings sections">
        {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">Create Account</h2>

      <div>
        <label htmlFor="email">Email address</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">We will never share your email.</p>
        {hasError && (
          <p id="email-error" role="alert">
            Please enter a valid email address.
          </p>
        )}
      </div>

      <button type="submit">Create Account</button>
    </form>
  );
}

色とコントラスト

:root {
  --text-primary: #1a1a1a;      /* 15.3:1 on white */
  --text-secondary: #595959;    /* 7.0:1 on white */
  --text-on-primary: #ffffff;   /* Ensure 4.5:1 on brand color */
  --border-focus: #0066cc;      /* Visible focus ring */
}

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

.error-message {
  color: #d32f2f;
  /* Don't rely on color alone - add icon or text prefix */
}
.error-message::before {
  content: "Error: ";
  font-weight: bold;
}

WCAG AAでは、通常のテキストに4.5:1、大きなテキスト(太字の18pxまたは通常の24px)に3:1のコントラスト比が求められます。

アンチパターン

  • クリック可能な要素にbuttonやaではなくdivやspanを使用する
  • 代わりとなるインジケーターを用意せずにフォーカスアウトラインを削除する
  • 情報を伝える手段として色だけに頼る(エラーには赤、成功には緑を使うなど)
  • 表示テキストがすでに要素のラベルになっているのにaria-labelを使用する
  • 一時停止する手段を用意せずにメディアを自動再生する
  • キーボードユーザー向けのスキップナビゲーションリンクがない

チェックリスト

  • すべてのインタラクティブ要素にキーボードでアクセスできる(Tab、Enter、Escape、矢印キー)
  • セマンティックHTMLのランドマークを使用している(nav、main、article、section)
  • 画像に説明的なaltテキストがある(装飾画像にはalt="")
  • 色のコントラストがWCAG AAを満たしている(通常のテキストは4.5:1、大きなテキストは3:1)
  • すべてのインタラクティブ要素でフォーカスインジケーターが見える
  • フォーム入力に対応する<label>要素がある
  • role="alert"を通じてエラーメッセージがスクリーンリーダーに通知される
  • スクリーンリーダー(VoiceOver、NVDA)とキーボードのみでページをテストしている

コメント