From 7623acba3e6697e50f1955857f2ebd8f837e7f8f Mon Sep 17 00:00:00 2001 From: Wesley Moses Date: Wed, 2 Nov 2022 09:26:01 +0200 Subject: [PATCH] [@mantine/core] Slider: Fix incorrect min/max values handling (#2839) * [@mantine/core] Select: only use open/close callback when value changes * [@mantine/core] Select: do not use early return * [@mantine/core] Menu - revert PR #2646 * [Mantine/core] Slider: fix min/max values * [@mantine/core] Slider: remove unneeded story * [@mantine/core] Slider: revert changes to minmax story --- .../utils/get-change-value/get-change-value.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mantine-core/src/Slider/utils/get-change-value/get-change-value.ts b/src/mantine-core/src/Slider/utils/get-change-value/get-change-value.ts index a18af5f0561..d9bb77bb07a 100644 --- a/src/mantine-core/src/Slider/utils/get-change-value/get-change-value.ts +++ b/src/mantine-core/src/Slider/utils/get-change-value/get-change-value.ts @@ -19,11 +19,12 @@ export function getChangeValue({ ? value : Math.min(Math.max(value, 0), containerWidth) / containerWidth; const dx = left * (max - min); - const minIsNegative = min <= 0; - const nextValue = - dx !== 0 ? Math.round(dx / step) * step + (minIsNegative ? min : 0) : Math.min(min, 0); - const nextValueWithPrecision = precision ? Number(nextValue.toFixed(precision)) : nextValue; - const finalValue = Math.min(nextValueWithPrecision, max); + const nextValue = (dx !== 0 ? Math.round(dx / step) * step : 0) + min; + const nextValueWithinStep = Math.max(nextValue - (nextValue % step), min); - return finalValue <= min ? min : finalValue; + if (precision !== undefined) { + return Number(nextValueWithinStep.toFixed(precision)); + } + + return nextValueWithinStep; }