Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/every-sloths-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@devup-ui/components': patch
---

Fix input value
5 changes: 5 additions & 0 deletions .changeset/kind-pumas-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@devup-ui/components': patch
---

Fix input value
13 changes: 9 additions & 4 deletions packages/components/src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface InputProps extends Omit<ComponentProps<'input'>, 'type'> {
}

export function Input({
defaultValue,
defaultValue = '',
value: valueProp,
onChange: onChangeProp,
typography,
Expand All @@ -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<HTMLInputElement>) => {
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 (
<Box
Expand Down Expand Up @@ -142,7 +147,7 @@ export function Input({
}}
transition="all 0.1s ease-in-out"
typography={typography}
value={valueProp ?? value}
value={innerValue}
{...props}
/>
{clearButtonVisible && <ClearButton onClick={handleClear} />}
Expand Down