Skip to content

Commit

Permalink
feat: improve handling of input in number task
Browse files Browse the repository at this point in the history
  • Loading branch information
procaconsul committed May 29, 2024
1 parent 425fdc3 commit 5ee89f2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/components/questionStructure/Task/variants/NumberTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ export interface NumberTaskProps extends TaskBaseProps<number> {
}

export const NumberTask: FC<NumberTaskProps> = ({ answer, onAnswerUpdate, disabled = false }) => {
const [inputValue, setInputValue] = useState(answer)
useEffect(() => onAnswerUpdate(inputValue), [inputValue, onAnswerUpdate])
const [inputValue, setInputValue] = useState<number | ''>(answer !== undefined ? answer : '')
useEffect(() => {
if (inputValue !== '') onAnswerUpdate(inputValue)
}, [inputValue, onAnswerUpdate])

function handleChange(e) {
setInputValue(parseInt(e.target.value))
}
const handleChange = (e) => setInputValue(e.target.value ? Number(e.target.value) : '')

return (
<TextField.Root
value={answer}
value={inputValue}
onChange={handleChange}
type="number"
variant="soft"
Expand Down

0 comments on commit 5ee89f2

Please sign in to comment.