Skip to content

fix: drive the switch press feedback from pointer events instead of :active - #15

Open
kazuemon wants to merge 1 commit into
mainfrom
fix/switch-color-flicker
Open

kazuemon wants to merge 1 commit into
mainfrom
fix/switch-color-flicker

Conversation

@kazuemon

@kazuemon kazuemon commented Sep 17, 2026 •

Copy link
Copy Markdown
Owner

現象

タッチで速く押すと、トグルのノブが切り替わったあとに縮んで戻る(ADR-0112 の色のちらつきを調べる途中で見つけたもの。色の件は #16 で直した)。

原因

ノブの縮み(押しているあいだ 0.92 倍)と行の塗りを CSS の :active で付けていた。Chrome はタッチで速く押すと、スクロールと区別するために :active を指を置いた瞬間には付けず、離したあと(click の直後)に 100〜150ms だけ付ける。付くかどうかは押し方で変わる(再現で 5 回押すと 2 回)。トグルは離した瞬間に切り替わるので、ノブが滑り始めてから縮み、130ms ほどして戻る。マウスでは起きない。

直し

  • 押しているあいだを :active ではなく pointer イベント(pointerdown 〜 pointerup・pointercancel・pointerleave)で部品が持ち、トラックに data-pressing を付ける(src/components/switch/use-pressed.ts)。Base UI が data-pressed を「ON・開いている」に使うので別の名前
  • ノブの縮み・行の塗りの見た目(ADR-0067)は変えない。見た目の基準画像も変わらない
  • 「状態」のストーリーの押下の列は data-pressing で作る
  • ADR-0113 と backlog を更新。チェックボックス・ラジオ・ボタンの :active も同じ挙動になりうるので、backlog に残した

確かめ

  • Storybook でタッチを再現し、フレームごとにノブの白いピクセルを数えた。直す前は離したあとに 474 → 420 → 483(縮んで戻る)、直したあとは置いているあいだだけ 483 → 421 で、離したあとは戻りながら滑る
  • pnpm typecheck・pnpm lint・pnpm format:check・pnpm test src/components/switch(7 件)

🤖 Generated with Claude Code

…active

On touch, Chrome applies :active after a quick tap has already toggled
the switch, so the knob shrank and popped back while sliding. Hold the
pressed state from pointerdown to pointerup and mark the track with
data-pressing (Base UI uses data-pressed for a lasting on/open state),
keeping the look from ADR-0067. Recorded in ADR-0113.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@kazuemon
kazuemon force-pushed the fix/switch-color-flicker branch from f751376 to dc2a8e3 Compare September 18, 2026 00:24
@kazuemon kazuemon changed the title fix: drive the switch press feedback from pointer events fix: drive the switch press feedback from pointer events instead of :active Sep 18, 2026

This branch has not been deployed

No deployments
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