From e7f23c9859cec2bad56dbd11a4b12615798141c8 Mon Sep 17 00:00:00 2001 From: yujinghan <57479283+yujinghan@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:10:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=84=E7=90=86inputRange=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=A4=A7=E6=95=B0=E9=A1=B5=E9=9D=A2=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#8651)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/src/components/Range.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/amis-ui/src/components/Range.tsx b/packages/amis-ui/src/components/Range.tsx index 333110fed..a074df720 100644 --- a/packages/amis-ui/src/components/Range.tsx +++ b/packages/amis-ui/src/components/Range.tsx @@ -383,11 +383,16 @@ export class Range extends React.Component { getStepValue(value: number, step: number) { const surplus = value % step; let result = 0; + let closeNum = Math.floor(value - (value % step)); // 余数 >= 步长一半 -> 向上取 // 余数 < 步长一半 -> 向下取 const _value = surplus >= step / 2 ? value : safeSub(value, step); while (result <= _value) { - result = safeAdd(result, step); + if (step < 1 || result === 0 || result === closeNum) { + result = safeAdd(result, step); + } else { + result = closeNum; + } } return result; }