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 and lme-axelor committed Dec 5, 2024
1 parent f447f5b commit a5c5403
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 @@ -25,6 +25,10 @@ import {
import {ThemeColors, useThemeColor} from '../../../theme';
import {Input} from '../../atoms';
import IncrementButton from './IncrementButton';
import {
OUTSIDE_INDICATOR,
useClickOutside,
} from '../../../hooks/use-click-outside';

const cutDecimalExcess = number => {
if (number == null) {
Expand Down Expand Up @@ -77,6 +81,9 @@ const Increment = ({
}: IncrementProps) => {
const Colors = useThemeColor();
const inputRef = useRef<any>(null);
const clickOutside = useClickOutside({
wrapperRef: inputRef,
});

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

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

const handleEndInput = () => {
const handleEndInput = useCallback(() => {
const unformattedValue = defaultFormatting
? valueQty.replaceAll(',', '.')
: valueQty;
Expand All @@ -169,7 +176,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 a5c5403

Please sign in to comment.