Skip to content

Phase 2 (1/5): touch support for the vote map's district tooltip - #458

Open
JeffreyBLewis wants to merge 1 commit into
mobile-chart-sizingfrom
touch-tooltips-map
Open

Phase 2 (1/5): touch support for the vote map's district tooltip#458
JeffreyBLewis wants to merge 1 commit into
mobile-chart-sizingfrom
touch-tooltips-map

Conversation

@JeffreyBLewis

Copy link
Copy Markdown
Collaborator

Summary

Stacks on #457 so this diff only shows the new commit, `6a6e4cd`.

First of the 5 tooltip sites from #449 (Phase 2 of the mobile UI plan). Chart tooltips bound only to `mouseover`/`mouseout`/`mousemove` are invisible on touch devices. Starting with the vote page's map tooltip, the most visible case.

Refactored the three anonymous mouseover/mouseout/mousemove handlers into named local functions so they can be reused for touch, with no behavior change for mouse users. Added `addTouchTooltip(selection, showFn, hideFn)`, gated on `matchMedia('(pointer: coarse)')`.

A real bug caught by testing, not by inspection: my first attempt just added a click binding alongside the existing hover ones. Headless-Chromium testing showed the tooltip appearing and then immediately disappearing on a real tap. Traced it to a synthetic `mouseout` event that reliably fires right after a tap (apparently once the resulting filter change redraws the chart) -- touch-to-mouse-event synthesis on tap is real but not reliable enough to layer tap handling on top of. Fixed by dropping the hover bindings entirely on coarse-pointer devices and driving the tooltip purely from taps: show on tap, hide on a tap anywhere outside the map.

Test plan

Verified with headless Chromium (Playwright):

  • Desktop (mouse): hover still shows/hides the tooltip exactly as before
  • Touch (iPhone 13 emulation): tapping a state shows the tooltip with correct content AND still applies the existing tap-to-filter behavior; tapping elsewhere dismisses it; no page errors
  • Full existing 36-check suite from the prior three commits on this branch still passes
  • Manual check on an actual touch device, if you get a chance

Remaining Phase 2 sites (`party.js` x2, `committee.js`, `personIdeology.js`, `district.js`) will follow as separate, similarly-verified PRs rather than one large batch.

🤖 Generated with Claude Code

https://claude.ai/code/session_013KJMYfgTNsxrmjHZpZKAHT

…f 5)

Phase 2 of the mobile UI plan (#449): chart tooltips bound only to
mouseover/mouseout/mousemove are invisible on touch devices, which have
no hover. Starting with the vote page's map tooltip since it's the most
visible case and I already know this file well from the chart-sizing
work.

Refactored the three anonymous mouseover/mouseout/mousemove handlers
into named local functions (showDistrictTooltip/hideDistrictTooltip/
positionDistrictTooltip) so they can be reused for touch, with no
behavior change for mouse users.

Added addTouchTooltip(selection, showFn, hideFn), gated on
matchMedia('(pointer: coarse)'). Initially tried just adding a click
binding alongside the existing hover ones, but headless-Chromium testing
caught a real problem: touch devices synthesize a mouseover/mousemove/
click sequence for a tap, but unreliably -- a synthetic mouseout
consistently fired right after the tap (apparently once the resulting
filter change redraws the chart), which hid the tooltip the instant it
appeared. So for coarse-pointer devices this drops the hover bindings
entirely instead, and drives the tooltip purely from taps: show on tap,
hide on a tap anywhere outside the map.

Verified with headless Chromium (Playwright), added as permanent checks
in the scratch verification suite:
- Desktop (mouse): hover still shows/hides exactly as before
- Touch (iPhone 13 emulation): tapping a state shows the tooltip with
  correct content AND still applies the existing tap-to-filter behavior;
  tapping elsewhere dismisses it; no page errors
- Full existing 36-check suite from the prior three commits still passes

Remaining Phase 2 sites (party.js x2, committee.js, personIdeology.js,
district.js) to follow as separate, similarly-verified changes rather
than one large batch, given today's lesson about over-broad changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013KJMYfgTNsxrmjHZpZKAHT
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