Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 1bf71de

Browse files
committed
Make price slider accurately represent the selected price independently from step (#1453)
1 parent a52690f commit 1bf71de

File tree

1 file changed

+11
-11
lines changed
  • assets/js/base/components/price-slider

1 file changed

+11
-11
lines changed

assets/js/base/components/price-slider/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,16 @@ const PriceSlider = ( {
8181
};
8282
}
8383

84-
// Normalize to whatever is the closest step (because range input will
85-
// only jump to the closest step in the range).
86-
const min = Math.round( minPrice / step ) * step;
87-
const max = Math.round( maxPrice / step ) * step;
88-
8984
const low =
9085
Math.round(
9186
100 *
92-
( ( min - minConstraint ) /
87+
( ( minPrice - minConstraint ) /
9388
( maxConstraint - minConstraint ) )
9489
) - 0.5;
9590
const high =
9691
Math.round(
9792
100 *
98-
( ( max - minConstraint ) /
93+
( ( maxPrice - minConstraint ) /
9994
( maxConstraint - minConstraint ) )
10095
) + 0.5;
10196

@@ -162,8 +157,8 @@ const PriceSlider = ( {
162157
);
163158
const targetValue = event.target.value;
164159
const currentValues = isMin
165-
? [ targetValue, maxPrice ]
166-
: [ minPrice, targetValue ];
160+
? [ Math.round( targetValue / step ) * step, maxPrice ]
161+
: [ minPrice, Math.round( targetValue / step ) * step ];
167162
const values = constrainRangeSliderValues(
168163
currentValues,
169164
minConstraint,
@@ -252,6 +247,11 @@ const PriceSlider = ( {
252247
! hasValidConstraints && 'is-disabled'
253248
);
254249

250+
const minRangeStep =
251+
minRange && document.activeElement === minRange.current ? step : 1;
252+
const maxRangeStep =
253+
maxRange && document.activeElement === maxRange.current ? step : 1;
254+
255255
return (
256256
<div className={ classes }>
257257
<div
@@ -274,7 +274,7 @@ const PriceSlider = ( {
274274
) }
275275
value={ minPrice || 0 }
276276
onChange={ rangeInputOnChange }
277-
step={ step }
277+
step={ minRangeStep }
278278
min={ minConstraint }
279279
max={ maxConstraint }
280280
ref={ minRange }
@@ -289,7 +289,7 @@ const PriceSlider = ( {
289289
) }
290290
value={ maxPrice || 0 }
291291
onChange={ rangeInputOnChange }
292-
step={ step }
292+
step={ maxRangeStep }
293293
min={ minConstraint }
294294
max={ maxConstraint }
295295
ref={ maxRange }

0 commit comments

Comments
 (0)