File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
packages/components/src/components/Input Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ interface InputProps extends Omit<ComponentProps<'input'>, 'type'> {
3838}
3939
4040export 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 } /> }
You can’t perform that action at this time.
0 commit comments