Skip to content

Commit e3129b1

Browse files
committed
Fix input value
1 parent 14a16e8 commit e3129b1

File tree

1 file changed

+9
-4
lines changed
  • packages/components/src/components/Input

1 file changed

+9
-4
lines changed

packages/components/src/components/Input/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface InputProps extends Omit<ComponentProps<'input'>, 'type'> {
3838
}
3939

4040
export function Input({
41-
defaultValue,
41+
defaultValue = '',
4242
value: valueProp,
4343
onChange: onChangeProp,
4444
typography,
@@ -54,16 +54,21 @@ export function Input({
5454
onClear,
5555
...props
5656
}: InputProps) {
57-
const [value, setValue] = useState(defaultValue || '')
57+
const [value, setValue] = useState(defaultValue)
58+
5859
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
5960
setValue(e.target.value)
6061
onChangeProp?.(e)
6162
}
63+
6264
const handleClear = () => {
6365
setValue('')
6466
onClear?.()
6567
}
66-
const clearButtonVisible = value && !disabled && allowClear
68+
69+
const innerValue = valueProp ?? value
70+
71+
const clearButtonVisible = !!innerValue && !disabled && allowClear
6772

6873
return (
6974
<Box
@@ -142,7 +147,7 @@ export function Input({
142147
}}
143148
transition="all 0.1s ease-in-out"
144149
typography={typography}
145-
value={valueProp ?? value}
150+
value={innerValue}
146151
{...props}
147152
/>
148153
{clearButtonVisible && <ClearButton onClick={handleClear} />}

0 commit comments

Comments
 (0)