From f6754e7d09395abb3e117419eaf5d970ba1b7f4b Mon Sep 17 00:00:00 2001 From: Ty Tremblay Date: Fri, 23 Feb 2024 12:56:04 -0500 Subject: [PATCH] fix number field resets, add min and max length to text fields --- src/components/inputs/ConfigurableInput.tsx | 1 + src/components/inputs/NumberInput.tsx | 7 +++++-- src/components/inputs/StringInput.tsx | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/inputs/ConfigurableInput.tsx b/src/components/inputs/ConfigurableInput.tsx index dc31411..7203b46 100644 --- a/src/components/inputs/ConfigurableInput.tsx +++ b/src/components/inputs/ConfigurableInput.tsx @@ -51,6 +51,7 @@ export default function ConfigurableInput(props: ConfigurableInputProps) { key={input.title} {...input} onChange={handleChange} + defaultValue={input.defaultValue} section={props.section} /> ); diff --git a/src/components/inputs/NumberInput.tsx b/src/components/inputs/NumberInput.tsx index ebfdb26..bd03d6a 100644 --- a/src/components/inputs/NumberInput.tsx +++ b/src/components/inputs/NumberInput.tsx @@ -2,6 +2,7 @@ import React from 'react'; import BaseInputProps from './BaseInputProps'; export interface NumberInputProps extends BaseInputProps { + value?: number; min?: number; max?: number; defaultValue?: number; @@ -9,17 +10,19 @@ export interface NumberInputProps extends BaseInputProps { export default function NumberInput(data: NumberInputProps) { function handleChange(e: React.ChangeEvent) { - data.onChange(e.currentTarget.value); e.preventDefault(); + data.onChange(e.currentTarget.value); } + console.log(data); + return ( diff --git a/src/components/inputs/StringInput.tsx b/src/components/inputs/StringInput.tsx index aefffa8..16a94bb 100644 --- a/src/components/inputs/StringInput.tsx +++ b/src/components/inputs/StringInput.tsx @@ -23,6 +23,8 @@ export default function StringInput(props: StringInputProps) { onChange={handleChange} defaultValue={data?.defaultValue || ''} value={data?.value || ''} - > + maxlength={props.max} + minlength={props.min} + /> ); }