Repository navigation
fix(useDoubleClick): handle keyboard and programmatic clicks - #579
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 6839941 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
KooYS
marked this pull request as ready for review
October 27, 2026 07:34
mnxmnz
approved these changes
Oct 28, 2026
mnxmnz
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix and the clear before/after table! 👍
I checked it in Chromium too, and the new branch only catches keyboard and programmatic clicks, as intended 🙌
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #579 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 70 70
Lines 2307 2311 +4
Branches 747 751 +4
=========================================
+ Hits 2307 2311 +4 🚀 New features to boost your workflow:
|
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
When the handler returned by
useDoubleClickis attached to a native button, activating it with Enter or Space does not invoke the providedclickcallback. The browser dispatches a click event, but the hook ignores it because its click count is zero. This PR preserves that single-click activation; it does not map keyboard input todoubleClick.Reproduction:
<Repro />and press Tab to focus the button.clickis logged once, like a plain<button onClick>. Actual: nothing is logged.Cause: keyboard activation (and
element.click()) dispatches a click withevent.detail === 0, while the hook only handlesdetail1 and 2. Such a click ran neither callback, and becauseclearClickTimeout()ran first it also cancelled a pending single click from the mouse.Fix:
detail === 0now runsclickimmediately and returns. These activations do not participate in the pointer click-count sequence, so this implementation invokesclickwithout waiting for a second pointer click. The return sits beforeclearClickTimeout()so the click stays independent of the mouse: a pending mouse click still fires after its delay (when the two overlap, the callbacks can run in reverse order).doubleClickis still only called fordetail === 2, and the mouse path is unchanged.Docs: the JSDoc description and the
delayparam now saydelayapplies to pointer single clicks and that clicks without a click count runclickimmediately; the generated and localized docs and the plugin skill reference follow. Patch changeset included.Verification
Real Chrome 156 (headless, Playwright mouse/keyboard input), React 19 production build,
delay250ms, 350ms wait;mainand this branch measured in the same session. Calls ofclick/doubleClick:mainbutton.click()Browser verification covers Chrome only; Safari, Firefox, and assistive technologies were not tested.
Tests: 8 new
detail === 0tests (7 fail onmain) and an SSR test; coverage stays at 100%.Self-review:
vi.restoreAllMocks()is added to the sharedafterEachinuseDoubleClick.spec.tsxbecause the existing unmount test'swindow.clearTimeoutspy was never restored and leaked into the appended tests (window.clearTimeout is not a function).Checklist
yarn run fixto format and lint the code and docs? (ran the check-onlyyarn test:lint/yarn test:format, both clean)yarn run test:coverageto make sure there is no uncovered line?