fix: do not allow zeroes (#3583)

This commit is contained in:
Zach Pomerantz 2022-03-23 14:07:41 -04:00 committed by GitHub
parent 24734e6a34
commit eb6c4d464a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,5 @@
import styled, { css } from 'lib/theme'
import { forwardRef, HTMLProps, useCallback } from 'react'
import { ChangeEvent, forwardRef, HTMLProps, useCallback } from 'react'
const Input = styled.input`
-webkit-appearance: textfield;
@ -81,13 +81,13 @@ const NumericInput = forwardRef<HTMLInputElement, EnforcedNumericInputProps>(fun
ref
) {
const validateChange = useCallback(
(event) => {
const nextInput = enforcer(event.target.value.replace(/,/g, '.'))
if (nextInput !== null) {
(event: ChangeEvent<HTMLInputElement>) => {
const nextInput = enforcer(event.target.value.replace(/,/g, '.'))?.replace(/^0+$/, '0')
if (nextInput !== undefined) {
onChange(nextInput)
}
},
[onChange, enforcer]
[enforcer, onChange]
)
return (