Commit b4bd2973 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: update input when prefixing 0 to decimal (#3487)

parent a071b8ad
import JSBI from 'jsbi'
import styled, { css } from 'lib/theme' import styled, { css } from 'lib/theme'
import { forwardRef, HTMLProps, useCallback, useEffect, useState } from 'react' import { forwardRef, HTMLProps, useCallback, useEffect, useState } from 'react'
...@@ -78,12 +77,16 @@ interface EnforcedNumericInputProps extends NumericInputProps { ...@@ -78,12 +77,16 @@ interface EnforcedNumericInputProps extends NumericInputProps {
} }
function isNumericallyEqual(a: string, b: string) { function isNumericallyEqual(a: string, b: string) {
const [aInteger, aDecimal] = a.split('.') const [aInteger, aDecimal] = toParts(a)
const [bInteger, bDecimal] = b.split('.') const [bInteger, bDecimal] = toParts(b)
return ( return aInteger === bInteger && aDecimal === bDecimal
JSBI.equal(JSBI.BigInt(aInteger ?? 0), JSBI.BigInt(bInteger ?? 0)) &&
JSBI.equal(JSBI.BigInt(aDecimal ?? 0), JSBI.BigInt(bDecimal ?? 0)) function toParts(num: string) {
) let [integer, decimal] = num.split('.')
integer = integer?.match(/([1-9]\d*)/)?.[1] || ''
decimal = decimal?.match(/(\d*[1-9])/)?.[1] || ''
return [integer, decimal]
}
} }
const NumericInput = forwardRef<HTMLInputElement, EnforcedNumericInputProps>(function NumericInput( const NumericInput = forwardRef<HTMLInputElement, EnforcedNumericInputProps>(function NumericInput(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment