Skip to content

Commit

Permalink
Merge pull request #698 from strapi/fix/numberinput-parser
Browse files Browse the repository at this point in the history
NumberInput: Fix value assignment during focus
  • Loading branch information
HichamELBSI authored Sep 20, 2022
2 parents 084ba39 + 966436e commit 852cdd8
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/strapi-design-system/src/NumberInput/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const NumberInput = React.forwardRef(
const [inputValue, setInputValue] = useState(value === undefined || value === null ? INITIAL_VALUE : String(value));
const generatedId = useId('numberinput', id);
const numberParserRef = useRef(new NumberParser(getDefaultLocale()));
const numberFormaterRef = useRef(new NumberFormatter(getDefaultLocale(), { maximumSignificantDigits: 21 }));
const numberFormaterRef = useRef(new NumberFormatter(getDefaultLocale(), { maximumFractionDigits: 20 }));

const handleChange = (e) => {
const nextValue = e.target.value;
Expand Down Expand Up @@ -143,9 +143,7 @@ export const NumberInput = React.forwardRef(
};

const handleFocus = () => {
if (value !== undefined) {
setInputValue(String(numberParserRef.current.format(inputValue) ?? INITIAL_VALUE));
}
setInputValue(inputValue ?? INITIAL_VALUE);
};

const handleBlur = () => {
Expand Down

0 comments on commit 852cdd8

Please sign in to comment.