-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor NumericInput events to one onChange event, handle onPaste, a…
…dd important test cases for NumericInput
- Loading branch information
1 parent
3b7d9b8
commit b2174b0
Showing
5 changed files
with
67 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { trimToMaxDecimals } from '../../../../shared/parseNumbers/maxDecimals'; | ||
|
||
const removeNonNumericCharacters = (value: string): string => value.replace(/[^0-9.]/g, ''); | ||
|
||
const replaceCommasWithDots = (value: string): string => value.replace(/,/g, '.'); | ||
|
||
/** | ||
* Handles the input change event to ensure the value does not exceed the maximum number of decimal places, | ||
* replaces commas with dots, and removes invalid non-numeric characters. | ||
* | ||
* @param e - The keyboard event triggered by the input. | ||
* @param maxDecimals - The maximum number of decimal places allowed. | ||
*/ | ||
export function handleOnChangeNumericInput(e: KeyboardEvent, maxDecimals: number): void { | ||
const target = e.target as HTMLInputElement; | ||
|
||
target.value = replaceCommasWithDots(target.value); | ||
|
||
target.value = removeNonNumericCharacters(target.value); | ||
|
||
target.value = trimToMaxDecimals(target.value, maxDecimals); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters