Skip to content

Commit

Permalink
refactor: manage format on blur/focus on the Increment input
Browse files Browse the repository at this point in the history
  • Loading branch information
vhu-axelor committed Nov 26, 2024
1 parent 78edee3 commit 857fb30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelogs/unreleased/87393.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Increment: modify format management on blur/focus",
"type": "refactor",
"packages": "ui"
}
13 changes: 11 additions & 2 deletions packages/ui/src/components/molecules/Increment/Increment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,17 @@ const Increment = ({
handleResult(newValue);
};

const handleStartInput = () => {
defaultFormatting &&
setValueQty(current => unformat(current).replace('.', decimalSpacer));

onFocus();
};

const handleEndInput = () => {
const unformattedValue = defaultFormatting ? unformat(valueQty) : valueQty;
const unformattedValue = defaultFormatting
? valueQty.replaceAll(',', '.')
: valueQty;

if (unformattedValue === '' || unformattedValue == null) {
handleResult(0);
Expand Down Expand Up @@ -176,7 +185,7 @@ const Increment = ({
value={valueQty != null ? String(valueQty) : ''}
onChange={input => setValueQty(input)}
keyboardType={keyboardType}
onSelection={onFocus}
onSelection={handleStartInput}
onEndFocus={handleEndInput}
readOnly={readonly}
/>
Expand Down

0 comments on commit 857fb30

Please sign in to comment.