From 947c9f70fbcbb0fd93858cec2b00e72e444d5905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AF=97=E6=B5=93?= <844670992@qq.com> Date: Tue, 18 Mar 2025 10:42:29 +0800 Subject: [PATCH] fix: improve InputNumber component step behavior and disabled state (#16044) --- .../components/base/input-number/index.tsx | 39 ++++++++++++++----- web/app/components/base/param-item/index.tsx | 1 + 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/web/app/components/base/input-number/index.tsx b/web/app/components/base/input-number/index.tsx index 316d863b48..71356620f0 100644 --- a/web/app/components/base/input-number/index.tsx +++ b/web/app/components/base/input-number/index.tsx @@ -12,10 +12,11 @@ export type InputNumberProps = { max?: number min?: number defaultValue?: number + disabled?: boolean } & Omit export const InputNumber: FC = (props) => { - const { unit, className, onChange, amount = 1, value, size = 'md', max, min, defaultValue, ...rest } = props + const { unit, className, onChange, amount = 1, value, size = 'md', max, min, defaultValue, disabled, ...rest } = props const isValidValue = (v: number) => { if (max && v > max) @@ -26,6 +27,8 @@ export const InputNumber: FC = (props) => { } const inc = () => { + if (disabled) return + if (value === undefined) { onChange(defaultValue) return @@ -36,6 +39,8 @@ export const InputNumber: FC = (props) => { onChange(newValue) } const dec = () => { + if (disabled) return + if (value === undefined) { onChange(defaultValue) return @@ -54,6 +59,7 @@ export const InputNumber: FC = (props) => { value={value} max={max} min={min} + disabled={disabled} onChange={(e) => { if (e.target.value === '') onChange(undefined) @@ -68,17 +74,30 @@ export const InputNumber: FC = (props) => { }} unit={unit} /> -
- -
diff --git a/web/app/components/base/param-item/index.tsx b/web/app/components/base/param-item/index.tsx index 68c980ad09..d1c7a7a093 100644 --- a/web/app/components/base/param-item/index.tsx +++ b/web/app/components/base/param-item/index.tsx @@ -53,6 +53,7 @@ const ParamItem: FC = ({ className, id, name, noTooltip, tip, step = 0.1, min={min} max={max} step={step} + amount={step} size='sm' value={value} onChange={(value) => {