Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/slider/src/RangeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const RangeSlider = ({
({
xy,
first,
last,
active,
memo = {
rect: sliderRef.current?.getBoundingClientRect(),
handle: Handle.Lower,
Expand Down Expand Up @@ -189,7 +189,16 @@ const RangeSlider = ({
onInput(internalValue.current.concat() as [number, number]);
}

if (last) {
if (!active) {
// When the user is dragging the slider, the useDrag callback is invoked multiple times,
// first with {first: true, active: true}, and finally with {last: true, active: false}.
//
// When the user is clicking (not dragging) the slider, the useDrag callback
// is invoked only once with {first: false, last: false, active: false}.
//
// We want to trigger onChange in both cases, and use {active: false} to detect when
// the user is done interacting with the filter (either clicking or dragging).

setIsDragging(false);
handleChange(dragValue, memo.handle);
const ref =
Expand Down
13 changes: 11 additions & 2 deletions packages/slider/src/RegularSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const RegularSlider = ({
({
xy,
first,
last,
active,
memo = {
rect: sliderRef.current?.getBoundingClientRect(),
},
Expand All @@ -128,7 +128,16 @@ const RegularSlider = ({

if (first) {
setIsDragging(true);
} else if (last) {
} else if (!active) {
// When the user is dragging the slider, the useDrag callback is invoked multiple times,
// first with {first: true, active: true}, and finally with {last: true, active: false}.
//
// When the user is clicking (not dragging) the slider, the useDrag callback
// is invoked only once with {first: false, last: false, active: false}.
//
// We want to trigger onChange in both cases, and use {active: false} to detect when
// the user is done interacting with the filter (either clicking or dragging).

setIsDragging(false);
handleChange(dragValue);
// focus the handle
Expand Down