Skip to content

Commit

Permalink
fix(suite): removing whitespaces from edgecase value
Browse files Browse the repository at this point in the history
Removing whitespaces from entered number value
  • Loading branch information
HelloBanksy authored and tomasklim committed Nov 23, 2024
1 parent cf5fb05 commit 480e152
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/suite/src/components/suite/NumberInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
ClipboardEvent,
FormEvent,
KeyboardEvent,
useCallback,
useLayoutEffect,
useRef,
useState,
KeyboardEvent,
ClipboardEvent,
FormEvent,
} from 'react';
import { Control, FieldValues, useController, UseControllerProps } from 'react-hook-form';

Expand Down Expand Up @@ -33,19 +33,20 @@ const cleanValueString = (value: string, locale: Locale) => {

const { decimalSeparator, thousandsSeparator } = getLocaleSeparators(locale);

const trimmedValue = value.replace(/\s/g, '');

// clean the entered number string if it's not convertible to Number or if it has a non-conventional format
if (
!Number.isNaN(Number(value)) &&
!Number.isNaN(Number(trimmedValue)) &&
thousandsSeparator !== '.' &&
!hasLeadingZeroes(value) &&
value.at(0) !== '.' &&
value.at(-1) !== '.'
!hasLeadingZeroes(trimmedValue) &&
trimmedValue.at(0) !== '.' &&
trimmedValue.at(-1) !== '.'
) {
return value;
return trimmedValue;
}

let cleanedValue = value
.replace(/\s/g, '')
let cleanedValue = trimmedValue
.replaceAll(thousandsSeparator, '')
.replaceAll(decimalSeparator, '.');

Expand Down

0 comments on commit 480e152

Please sign in to comment.