Skip to content

Commit

Permalink
Merge pull request #26 from FRC2713/preserveDataOnReset
Browse files Browse the repository at this point in the history
fix number field resets, add min and max length to text fields
  • Loading branch information
tytremblay authored Feb 23, 2024
2 parents e335d89 + f6754e7 commit d81405b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/inputs/ConfigurableInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function ConfigurableInput(props: ConfigurableInputProps) {
key={input.title}
{...input}
onChange={handleChange}
defaultValue={input.defaultValue}
section={props.section}
/>
);
Expand Down
7 changes: 5 additions & 2 deletions src/components/inputs/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import React from 'react';
import BaseInputProps from './BaseInputProps';

export interface NumberInputProps extends BaseInputProps {
value?: number;
min?: number;
max?: number;
defaultValue?: number;
}

export default function NumberInput(data: NumberInputProps) {
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
data.onChange(e.currentTarget.value);
e.preventDefault();
data.onChange(e.currentTarget.value);
}

console.log(data);

return (
<input
className="w-full rounded py-2 dark:bg-gray-700 dark:text-white"
type="number"
min={data.min}
max={data.max}
value={data.defaultValue}
value={data.value || data.defaultValue || ''}
id={data.title}
onChange={handleChange}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/components/inputs/StringInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default function StringInput(props: StringInputProps) {
onChange={handleChange}
defaultValue={data?.defaultValue || ''}
value={data?.value || ''}
></textarea>
maxlength={props.max}
minlength={props.min}
/>
);
}

0 comments on commit d81405b

Please sign in to comment.