Closed lauterb closed 2 months ago
Conflicts. Think I need to rebase
Either of these sort of works for validation when the times are numbers, kind of slightly prefer the set to 0 version, it's a bit more intuitive when typing. Should maybe also check for less than zero or greater than the duration.
const validNum = (value: number ) => isNaN(value) ? 0 : value
const onSChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setStartTime(validNum(parseFloat(e.target.value)))
}
const onEChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newVal = parseFloat(e.target.value)
setEndTime(val=> !isNaN(newVal) ? newVal : val )
Now I remember since I just retried it that trying to format like this
<input type={"number"} step={"0.01"} value={startTime.toFixed(2)} onChange={onSChange}/>
gives some weird slightly counterintuitive behavior when typing.
In the stored-as-a-number version without formatting I can also get this kind of stuff when I decrement
We can go with formatting, but then the user has to highlight the part they want to change to be able to type properly.
Okay, tinkered some more and reasonably happy with this version. Waiting for the test to pass.
Still some tiny bit of weirdness about re-rendering when Nan that I will try not to worry about. See also https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/
It actually returns an empty string if it doesn't like something but doesn't re-render when I try to set the value
Ah, I can force a re-render by returning a string with a blank in it, " "
One key thing is rounding the number as above, instead of formatting at display time or not rounding at all.
I don't think anyone wants 3dp
If somebody wants more or less we can always make another number input box to set the precision.