diff --git a/.changeset/every-sloths-read.md b/.changeset/every-sloths-read.md new file mode 100644 index 00000000..86c15790 --- /dev/null +++ b/.changeset/every-sloths-read.md @@ -0,0 +1,5 @@ +--- +'@devup-ui/components': patch +--- + +Fix input value diff --git a/.changeset/kind-pumas-own.md b/.changeset/kind-pumas-own.md new file mode 100644 index 00000000..86c15790 --- /dev/null +++ b/.changeset/kind-pumas-own.md @@ -0,0 +1,5 @@ +--- +'@devup-ui/components': patch +--- + +Fix input value diff --git a/packages/components/src/components/Input/index.tsx b/packages/components/src/components/Input/index.tsx index 5d12ceee..7b3bb013 100644 --- a/packages/components/src/components/Input/index.tsx +++ b/packages/components/src/components/Input/index.tsx @@ -38,7 +38,7 @@ interface InputProps extends Omit, 'type'> { } export function Input({ - defaultValue, + defaultValue = '', value: valueProp, onChange: onChangeProp, typography, @@ -54,16 +54,21 @@ export function Input({ onClear, ...props }: InputProps) { - const [value, setValue] = useState(defaultValue || '') + const [value, setValue] = useState(defaultValue) + const handleChange = (e: React.ChangeEvent) => { setValue(e.target.value) onChangeProp?.(e) } + const handleClear = () => { setValue('') onClear?.() } - const clearButtonVisible = value && !disabled && allowClear + + const innerValue = valueProp ?? value + + const clearButtonVisible = !!innerValue && !disabled && allowClear return ( {clearButtonVisible && }