Skip to content

fix(target-size): ::before / ::after で広げたターゲット領域を考慮する - #386

Merged
ymrl merged 1 commit into
mainfrom
fix/target-size-pseudo-elements
Oct 1, 2026
Merged

ymrl merged 1 commit into
mainfrom
fix/target-size-pseudo-elements

Conversation

@ymrl

@ymrl ymrl commented Oct 1, 2026

Copy link
Copy Markdown
Owner

概要

ボタン本体は小さくても、::before / ::after 疑似要素でクリック領域を 24×24px 以上に広げている場合に、ターゲットサイズのルールが「Small target」を出していた問題を修正します。

変更内容

  • packages/rules/src/target-size/index.ts
    • 要素本体が 24px 未満のとき、getComputedStyle(element, "::before" | "::after") の width / height を確認し、どちらかが 24×24px 以上なら小さいターゲットとして扱わない
    • 描画中の疑似要素の width / height はレイアウト後の実寸が返るため、inset や top / bottom / left / right で大きさが決まる場合も判定できる
    • content がない、display: none、visibility: hidden、pointer-events: none の疑似要素はクリック領域にならないので除外
  • packages/rules/src/target-size/index.test.ts
    • 疑似要素で広げたケースのテストを追加(24×24 の ::before / ::after、inset で拡大、24px 未満、幅だけ 24px、および除外条件 4 種)
  • テストページ(TargetSizeTests.astro / .lang.ts)
    • 16×16px のボタンを ::before で 24×24px に広げた例を追加(en / ja)
  • changeset を追加(@a11y-visualizer/rules / @a11y-visualizer/browser-extension の patch)

既知の制約

疑似要素の箱の大きさを見る簡易的な判定のため、以下は実際のクリック領域と一致しない場合があります。

  • 親の overflow: hidden や clip-path で疑似要素が切り取られていても「十分」と判定する
  • transform: scale() やインライン配置で広げた場合は考慮しない

テスト

  • pnpm --filter=@a11y-visualizer/rules test(Chromium / Firefox): すべて通過
  • pnpm --filter=@a11y-visualizer/browser-extension compile: 通過
  • pnpm lint-fix: 済

🤖 Generated with Claude Code

A small control whose clickable area is expanded to at least 24x24px by a
::before or ::after pseudo-element is no longer reported as a small target.
Pseudo-elements without content, or with display: none, visibility: hidden
or pointer-events: none, are not counted.

Also add an example of a 16x16px button expanded by ::before to the target
size test page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymrl
ymrl merged commit c903667 into main Oct 1, 2026
8 checks passed
@ymrl
ymrl deleted the fix/target-size-pseudo-elements branch October 1, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant