Repository navigation
fix: track keyboard press synchronously for native range keys - #308
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Changes按键输入处理
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #308 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 364 368 +4
Branches 94 94
=========================================
+ Hits 364 368 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The colour picker's handles are native range inputs. While a value key is held (arrow keys, Page Up/Down, Home/End),
Handleris meant to keep the interaction open and callonChangeCompleteonly onkeyup. It tracked that with thekeyPressingstate, set inonKeyDown. A native range input fires itsinputevent in the same keydown turn, before React has committed that state update, so the change handler still sawkeyPressing === false, treated the change as a finished interaction and calledonChangeCompletewhile the key was still down (and again onkeyup).Handlernow also keeps the same flag in auseRef(keyPressingRef), set and cleared next to everysetKeyPressingcall (keydown, keyup, blur), and the change handler reads the ref. The state is still there for rendering; only the check in the change handler is synchronous.Test:
Should defer onChangeComplete until keyup for native range keysintests/index.test.tsxdispatches akeydown(PageDown), sets the range value and dispatchesinputinside oneact(), the order a native range input uses, and expectsonChangeonce andonChangeCompletenot at all untilkeyup. Onmasterit fails (expected "vi.fn()" to not be called at all, but actually been called 1 times) and it passes now.npm testpasses (3 files, 72 tests), andtsc --noEmitand Prettier are clean on the changed files. The test simulates the browser's event order; I did not try this in a real browser.Summary by CodeRabbit