[Slider] Commit keyboard inputs on key release instead of every step - #5604
Open
azeng4499 wants to merge 1 commit into
Open
[Slider] Commit keyboard inputs on key release instead of every step#5604azeng4499 wants to merge 1 commit into
azeng4499 wants to merge 1 commit into
Conversation
azeng4499
requested review from
atomiks,
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
August 31, 2026 23:07
commit: |
Bundle size
PerformanceTotal duration: 1,008.79 ms -65.87 ms(-6.1%) | Renders: 76 (+0) | Paint: 1,631.18 ms -117.51 ms(-6.7%) No significant changes — details Check out the code infra dashboard for more information about this PR. |
Contributor
Author
|
This could be breaking depending on how y'all define "breaking". |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
A slider can be adjusted two ways:
DraggingfiresonValueChangeon every pointer move, butonValueCommittedonly once the pointer is released.KeyboardfiresonValueCommittedon every step, causing each step's value to be continuous committed until key is released.The keyboard input values should only be committed once the user lets go, the same way dragging works. Committing on every keyboard step causes unnecessary commit callbacks, potentially slowing down the UI on expensive operations.
Fix
Defer the keyboard commit until the key is released:
SliderRoot—handleInputChangenow stashes keyboard values in apendingKeyboardValueRefinstead of committing immediately. A newcommitKeyboardValuecallback firesonValueCommittedonce with the pending value and clears the ref.SliderThumb— added anonKeyUphandler on the input that commits the pending value when a stepping key is released, plus a fallback inonBlurfor the rare case where thekeyupnever reaches the input.SliderRootContext— exposescommitKeyboardValueso the thumb calls logic owned by the root.Tests
Added tests to
SliderRoot.test.tsxto ensure keyboard input behavior is adhered.Closes #5595