diff --git a/packages/amis-ui/src/components/Range.tsx b/packages/amis-ui/src/components/Range.tsx index bebbbd840..19468c575 100644 --- a/packages/amis-ui/src/components/Range.tsx +++ b/packages/amis-ui/src/components/Range.tsx @@ -382,11 +382,12 @@ export class Range extends React.Component { */ getStepValue(value: number, step: number) { const surplus = value % step; - let curValue = value - surplus; + let curValue = 0; + const closeNum = value - surplus; // 余数 >= 步长一半 -> 向上取,value为正值的时候,使用 safeAdd,否则使用 safeSub - // 余数 < 步长一半 -> 向下取,使用 curValue + // 余数 < 步长一半 -> 向下取,使用 closeNum if (Math.abs(surplus) >= step / 2) { - curValue = value >= 0 ? safeAdd(curValue, step) : safeSub(curValue, step); + curValue = value >= 0 ? safeAdd(closeNum, step) : safeSub(closeNum, step); } /* let result = 0; diff --git a/packages/amis/__tests__/event-action/renderers/form/range.test.tsx b/packages/amis/__tests__/event-action/renderers/form/range.test.tsx index f770f6bcb..d8709400c 100644 --- a/packages/amis/__tests__/event-action/renderers/form/range.test.tsx +++ b/packages/amis/__tests__/event-action/renderers/form/range.test.tsx @@ -118,7 +118,7 @@ test('EventAction:inputRange', async () => { }); // 滑动 change - const slider = container.querySelector('.cxd-InputRange-handle')!; + const slider = container.querySelector('.cxd-InputRange-handle-icon')!; fireEvent.mouseDown(slider); fireEvent.mouseMove(slider, { clientX: 0,