mcpField
F
frontend-accessibility-best-practices

frontend-accessibility-best-practices

github.com/sergiodxaデザイン・UI92872 回インストール38 週間前に更新
リポジトリ

frontend-accessibility-best-practices について

frontend-accessibility-best-practicesは、Reactアプリの構築やレビューに使う、WCAGに沿ったガイドです。7つのルールで、セマンティックHTML、スクリーンリーダー、キーボード操作、ユーザー設定を扱います。

主な機能

  1. 017つのアクセシビリティルール
  2. 02セマンティックHTML構造の利用
  3. 03スクリーンリーダーへの通知
  4. 04キーボード操作とフォーカス管理
  5. 05視差効果の軽減設定への対応
  6. 06タッチターゲットのサイズ確認

活用シーン

  1. 01React UIコンポーネントの構築
  2. 02フォームと操作要素の実装
  3. 03動的コンテンツや通知の追加
  4. 04インターフェースのアクセシビリティレビュー

インストール

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

$npx skills add https://github.com/sergiodxa/agent-skills --skill frontend-accessibility-best-practices

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

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

rules/
aria-live-regions.md
focus-management.md
keyboard-navigation.md
reduced-motion.md
screen-reader-sr-only.md
semantic-html-landmarks.md
touch-targets.md

詳細

アクセシビリティのベストプラクティス

WCAG 標準に準拠した、インクルーシブな React アプリケーションを構築するためのアクセシビリティパターンです。セマンティック HTML、スクリーンリーダーのサポート、キーボード操作、ユーザー設定に重点を置いた、4 つのカテゴリにわたる 7 つのルールが含まれています。

適用するタイミング

次の場合に、これらのガイドラインを参照してください。

  • 新しい UI コンポーネントを作成するとき
  • フォームやインタラクティブな要素を構築するとき
  • 動的コンテンツや通知を追加するとき
  • ナビゲーションパターンを実装するとき
  • アクセシビリティの観点からコードをレビューするとき

ルールの概要

セマンティック HTML と構造(高)
semantic-html-landmarks - @rules/semantic-html-landmarks.md

ページ構造にはセマンティック HTML 要素を使用します。

// Bad: divs with class names
<div className="header">...</div>
<div className="nav">...</div>
<div className="content">...</div>

// Good: semantic elements
<header>...</header>
<nav aria-label={t("Primary")}>...</nav>
<main>...</main>
<footer>...</footer>
スクリーンリーダー(中)
screen-reader-sr-only - @rules/screen-reader-sr-only.md

視覚的に隠すテキストには sr-only クラスを使用します。

// Icon-only buttons need accessible labels
<Button variant="icon" onPress={onClose}>
  <XMarkIcon aria-hidden="true" />
  <span className="sr-only">{t("Close")}</span>
</Button>

// Visually hidden section headings
<section>
  <h2 className="sr-only">{t("Search results")}</h2>
  <SearchResultsList />
</section>
aria-live-regions - @rules/aria-live-regions.md

動的なコンテンツの変更をスクリーンリーダーに通知します。

// Error messages - announced immediately
{
  error && (
    <p role="alert" className="text-failure-600">
      {error}
    </p>
  );
}

// Status updates - announced politely
<div role="status" aria-live="polite">
  {t("{{count}} results found", { count })}
</div>;
キーボード操作とフォーカス(高)
keyboard-navigation - @rules/keyboard-navigation.md

キーボード操作を標準でサポートするセマンティック要素を使用します。

// Bad: div with onClick not keyboard accessible
<div onClick={handleClick}>Click me</div>

// Good: button has Enter/Space support
<button onClick={handleClick}>Click me</button>

// Good: react-aria Button handles everything
import { Button } from "react-aria-components";
<Button onPress={handlePress}>Click me</Button>
focus-management - @rules/focus-management.md

フォーカスインジケーターを視覚的に表示し、モーダル内にフォーカスを閉じ込めます。

// Always use focus-visible for focus styles
<button className="focus-visible:ring-2 focus-visible:ring-teal-600">
  Click me
</button>;

// react-aria Modal handles focus trapping automatically
import { Modal, Dialog } from "react-aria-components";
<Modal isOpen={isOpen}>
  <Dialog>{/* Focus automatically trapped here */}</Dialog>
</Modal>;
ユーザー設定(中)
reduced-motion - @rules/reduced-motion.md

prefers-reduced-motion の設定を尊重します。

import { usePrefersReducedMotion } from "~/hooks/use-prefers-reduced-motion";

// CSS approach
<div className="animate-bounce motion-reduce:animate-none">
  Bouncing content
</div>;

// JS approach
function AnimatedCounter({ value }) {
  let prefersReducedMotion = usePrefersReducedMotion();
  if (prefersReducedMotion) return <span>{value}</span>;
  return <CountUp target={value} />;
}
touch-targets - @rules/touch-targets.md

タッチターゲットが最小でも 44x44px になるようにします。

// Icon buttons need explicit sizing
<Button variant="icon" className="h-11 w-11">
  <XMarkIcon className="h-5 w-5" />
  <span className="sr-only">{t("Close")}</span>
</Button>

// Links need padding for tappable area
<Link to={href} className="block py-3 px-4">
  {label}
</Link>

主なファイル

  • app/components/heading.tsx - Region、Heading、Main コンポーネント
  • app/hooks/use-prefers-reduced-motion.ts - モーション低減用フック
  • app/components/field/field.tsx - アクセシブルなフォームフィールドコンポーネント

コメント