Repository navigation
fix: restore mouse hover after touchscreen use - #11052
Conversation
langz
left a comment
There was a problem hiding this comment.
Looks good! It's a small, targeted fix for a real issue.
Verified
- I confirmed the root cause: on
main,validateTouchreset the timestamp on every call, so continuous mouse movement keptdata-whatintent="touch"indefinitely. It could even swallow a real mouse click made right after moving the mouse. Measuring from the last touch event fixes both. - I ran the new tests against
main's implementation. All three fail withExpected: "mouse"/Received: "touch"and pass with this change, so they are proper regression tests. The "restarts the delay when touch movement continues" case also guards against only setting the timestamp onpointerdown. - I compared
mainand this branch on a fast tap (a compatibilitymousedown80 ms after the tap is still ignored), a slow tap, and pen hover followed by a mouse click. Both behave the same, so I see no regression for touch-only devices. - The JSDoc on
validateTouch("within 200 ms" of a touch) now matches the actual behavior.
Non-blocking, pre-existing (follow-up idea only)
Because the window starts at pointerdown, a tap held for more than 200 ms (without touch movement) lets the compatibility mousedown switch input and intent to mouse. This can bring back sticky hover on touch-only devices. It behaves the same on main, so it's out of scope here. If it matters, measuring from pointerup could be a follow-up.
No visual concerns: this is behavior-only, and visual regression and e2e checks pass.
langz
left a comment
There was a problem hiding this comment.
Review of 6ac22e1: Approve
The new commit acts on the follow-up from the earlier review: the 200 ms window now also restarts on touch release, so a held tap no longer lets the compatibility mousedown switch input back to mouse. I found no new defects. Tested merged with main at 4e63f4c.
Earlier findings
- Resolved: a tap held for more than 200 ms let the compatibility
mousedownswitch input and intent tomouse. In real Chromium, a 350 ms held tap (CDP touch events) now ends astouch/touch;mainends asmouse/mouse.
What I checked
- Trial merge with
mainat4e63f4c: no conflicts. Main has not changed these files since the PR's base. A real trial merge with the newermainatecaa2f5is also clean. Its two new commits (Flex and Card) do not touch these files. whatInput.test.tson the merge: 13 of 13 pass. The related suites (component-helper,Accordion,SidebarMenuResponsive,DrawerList,MenuIntegration,FocusRing): 339 tests pass. Two SCSS snapshot tests timed out under load and passed alone.- The new tests fail without the fix. With
main'swhatInput.ts, 5 of 13 fail. With the first commit'swhatInput.ts, the 2 held-tap tests (touchandpen) fail. The current head passes all 13. - Real browsers, on the
mainand PR previews, using synthetic events timed by the page:- Tap, then mouse moves 50 ms apart:
mainstaystouchin Chromium and Firefox. The PR switches tomouseabout 200 ms after the release. - Held tap (350 ms):
mainends asmouse/mouseand the PR astouch/touchin Chromium, Firefox and WebKit. - Quick tap: the PR keeps
touch/touchin all three engines. - A real mouse click 250 ms after a tap switches input and intent to
mouse. A mouse move 250 ms afterpointercancel(a touch that became a scroll) switches intent tomouse. Both behave the same onmainand the PR, in all three engines.
- Tap, then mouse moves 50 ms apart:
- Real taps (Playwright touch input) fire
pointerdown,pointerup, thenmousedownin all three engines. So listening topointerupcovers the compatibility event. - How this works with the
@media (any-hover: hover)guards in the touch-hover PRs (for example #11007 and #11053): those guards still checkdata-whatintent. On a hybrid device, whereany-hover: hoverstays true, they depend on this change to bring hover back after the mouse moves. Keyboard intent is not affected: the 200 ms check runs only while the current input istouch. - Listeners and SSR: one more capture listener is added in the same one-time
setUp, behind the existingdocument/windowguard. The module never removes listeners, so nothing new needs cleanup. - ESLint and Prettier on both files: clean.
CI on 6ac22e113b: all 23 checks passed. Rechecked just before posting: the head is still 6ac22e1.
After using the touchscreen on a device with both touch and a mouse, moving the mouse could leave hover styles turned off. Every mouse event restarted the 200 ms delay, so continuous movement could keep it going indefinitely.
Count the delay from the last touch event, including release. This also keeps a held tap from turning hover back on when the browser sends a compatibility mouse event after release. Mouse movement can restore hover after 200 ms, and the next touch turns it off again.
Keep the existing input tracking: a CSS query such as
@media (hover: hover)tells us whether the browser's primary pointer can hover. It does not reliably tell us whether the user just touched the screen or used the mouse. On a hybrid device it can stay true during touch, so it cannot provide the same switching behavior. See the CSS specification.