1
0
Fork 0

fix(gui): handle decimal inputs correctly

This commit is contained in:
Sean Sube 2023-01-08 13:25:02 -06:00
parent 2328c5f46a
commit d5c4040b07
2 changed files with 12 additions and 2 deletions

View File

@ -80,10 +80,11 @@ export function Img2Img(props: Img2ImgProps) {
setParams(newParams); setParams(newParams);
}} /> }} />
<NumericField <NumericField
decimal
label='Width' label='Width'
min={0} min={0}
max={1} max={1}
step='any' step={0.1}
value={strength} value={strength}
onChange={(value) => { onChange={(value) => {
setStrength(value); setStrength(value);

View File

@ -2,7 +2,16 @@ import { doesExist } from '@apextoaster/js-utils';
import { TextField } from '@mui/material'; import { TextField } from '@mui/material';
import * as React from 'react'; import * as React from 'react';
export function parseNumber(num: string, decimal=false): number {
if (decimal) {
return parseFloat(num);
} else {
return parseInt(num, 10);
}
}
export interface ImageControlProps { export interface ImageControlProps {
decimal?: boolean;
label: string; label: string;
min: number; min: number;
max: number; max: number;
@ -22,7 +31,7 @@ export function NumericField(props: ImageControlProps) {
value={value} value={value}
onChange={(event) => { onChange={(event) => {
if (doesExist(props.onChange)) { if (doesExist(props.onChange)) {
props.onChange(parseInt(event.target.value, 10)); props.onChange(parseNumber(event.target.value, props.decimal));
} }
}} }}
/>; />;