From 1349ef4aa0cffaec6454bc86f4e83e41f8b941d6 Mon Sep 17 00:00:00 2001 From: sansiro Date: Tue, 9 Aug 2022 10:49:28 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20input-number=E3=80=81input-range?= =?UTF-8?q?=E3=80=81checkbox=20=E5=8D=95=E6=B5=8B=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=A1=A5=E5=85=85=20&=20range=20style=20=E7=99=BE=E5=88=86?= =?UTF-8?q?=E6=AF=94=E6=9C=80=E5=A4=9A=E4=BF=9D=E7=95=99=E4=B8=A4=E4=BD=8D?= =?UTF-8?q?=20(#5076)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * checkbox 单测补充 * input-number 单测补充 * input-range 单测补充 & range style 百分比最多保留两位 Co-authored-by: tooeast --- packages/amis-ui/src/components/Range.tsx | 3 +- .../Form/__snapshots__/checkbox.test.tsx.snap | 268 +++++ .../Form/__snapshots__/number.test.tsx.snap | 857 ++++++++++++++++ .../Form/__snapshots__/range.test.tsx.snap | 966 +++++++++++++----- .../renderers/Form/checkbox.test.tsx | 90 +- .../__tests__/renderers/Form/number.test.tsx | 183 +++- .../__tests__/renderers/Form/range.test.tsx | 138 ++- 7 files changed, 2220 insertions(+), 285 deletions(-) diff --git a/packages/amis-ui/src/components/Range.tsx b/packages/amis-ui/src/components/Range.tsx index c7399a656..e9dc531a5 100644 --- a/packages/amis-ui/src/components/Range.tsx +++ b/packages/amis-ui/src/components/Range.tsx @@ -78,7 +78,8 @@ const MARKS_REG = /^[0-9]+(\.?[0-9]+)?%$/; * @returns position.left */ const valueToOffsetLeft = (value: any, min: number, max: number) => - ((value - min) * 100) / (max - min) + '%'; + // 最多保留两位小数,且尽量取整 + Math.floor(((value - min) * 10000) / (max - min)) / 100 + '%'; /** * 滑块handle diff --git a/packages/amis/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap b/packages/amis/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap index b29104e58..53b31778d 100644 --- a/packages/amis/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap +++ b/packages/amis/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap @@ -109,6 +109,274 @@ exports[`Renderer:checkbox 1`] = ` + + + +`; + +exports[`Renderer:checkbox with checked 1`] = ` +
+
+
+

+ + + The form + + +

+
+
+
+ +
+ +
+ +
+
+ +
+