Fix event spread in PriceField (#1996)
* Fix event spread in PriceField * Use synthetic event Co-authored-by: Dominik Żegleń <flesz3@o2.pl>
This commit is contained in:
parent
207ce6d031
commit
0f237ad2e7
1 changed files with 13 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { InputAdornment, TextField, TextFieldProps } from "@material-ui/core";
|
import { InputAdornment, TextField, TextFieldProps } from "@material-ui/core";
|
||||||
import { InputProps } from "@material-ui/core/Input";
|
import { InputProps } from "@material-ui/core/Input";
|
||||||
|
import { FormChange } from "@saleor/hooks/useForm";
|
||||||
import { makeStyles } from "@saleor/macaw-ui";
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
import React, { useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
|
@ -70,22 +71,27 @@ export const PriceField: React.FC<PriceFieldProps> = props => {
|
||||||
[currencySymbol]
|
[currencySymbol]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleChange: React.ChangeEventHandler<HTMLInputElement> = e => {
|
const handleChange: FormChange = e => {
|
||||||
let newValue = e.target.value;
|
let value = e.target.value;
|
||||||
const splitCharacter = findPriceSeparator(newValue);
|
const splitCharacter = findPriceSeparator(value);
|
||||||
const [integerPart, decimalPart] = e.target.value.split(splitCharacter);
|
const [integerPart, decimalPart] = value.split(splitCharacter);
|
||||||
|
|
||||||
if (maxDecimalLength === 0 && decimalPart) {
|
if (maxDecimalLength === 0 && decimalPart) {
|
||||||
// this shouldn't happen - decimal character should be ignored
|
// this shouldn't happen - decimal character should be ignored
|
||||||
newValue = integerPart;
|
value = integerPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decimalPart?.length > maxDecimalLength) {
|
if (decimalPart?.length > maxDecimalLength) {
|
||||||
const shortenedDecimalPart = decimalPart.slice(0, maxDecimalLength);
|
const shortenedDecimalPart = decimalPart.slice(0, maxDecimalLength);
|
||||||
newValue = `${integerPart}${splitCharacter}${shortenedDecimalPart}`;
|
value = `${integerPart}${splitCharacter}${shortenedDecimalPart}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange({ ...e, target: { ...e.target, value: newValue } });
|
onChange({
|
||||||
|
target: {
|
||||||
|
name: e.target.name,
|
||||||
|
value
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyPress: TextFieldProps["onKeyDown"] = e => {
|
const handleKeyPress: TextFieldProps["onKeyDown"] = e => {
|
||||||
|
|
Loading…
Reference in a new issue