Skip to content

Commit

Permalink
fix: issue on save for the Increment value on form (#823)
Browse files Browse the repository at this point in the history
* RM#87714
  • Loading branch information
vhu-axelor authored Dec 4, 2024
1 parent b4dae08 commit bbdfad3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelogs/unreleased/87714.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Increment: save when click outside the input",
"type": "fix",
"packages": "ui"
}
17 changes: 15 additions & 2 deletions packages/ui/src/components/molecules/Increment/Increment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import {ThemeColors, useThemeColor} from '../../../theme';
import {Input} from '../../atoms';
import IncrementButton from './IncrementButton';
import {useDigitFormat} from '../../../hooks/use-digit-format';
import {
OUTSIDE_INDICATOR,
useClickOutside,
} from '../../../hooks/use-click-outside';

interface IncrementProps {
style?: any;
Expand Down Expand Up @@ -67,6 +71,9 @@ const Increment = ({
const Colors = useThemeColor();
const cutDecimalExcess = useDigitFormat();
const inputRef = useRef<any>(null);
const clickOutside = useClickOutside({
wrapperRef: inputRef,
});

const [valueQty, setValueQty] = useState<string>(value);

Expand Down Expand Up @@ -147,7 +154,7 @@ const Increment = ({
handleResult(newValue);
};

const handleEndInput = () => {
const handleEndInput = useCallback(() => {
const unformattedValue = defaultFormatting
? valueQty.replaceAll(',', '.')
: valueQty;
Expand All @@ -159,7 +166,13 @@ const Increment = ({
}

onBlur();
};
}, [defaultFormatting, handleResult, onBlur, valueQty]);

useEffect(() => {
if (clickOutside === OUTSIDE_INDICATOR) {
handleEndInput();
}
}, [clickOutside, handleEndInput]);

const handleFocus = () => {
if (defaultFormatting) {
Expand Down

0 comments on commit bbdfad3

Please sign in to comment.