mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-30 10:14:53 -05:00
Fix budget amount not saved when clicking on another budget cell (#1965)
* Fix budget amount not saved when clicking on another budget cell * Release notes
This commit is contained in:
committed by
GitHub
parent
67b9143dfc
commit
0d1b962b2f
@@ -1,4 +1,4 @@
|
||||
import React, { type MutableRefObject, useRef, useState } from 'react';
|
||||
import React, { type Ref, useRef, useState, useEffect } from 'react';
|
||||
|
||||
import evalArithmetic from 'loot-core/src/shared/arithmetic';
|
||||
import { amountToInteger } from 'loot-core/src/shared/util';
|
||||
@@ -14,7 +14,7 @@ import useFormat from '../spreadsheet/useFormat';
|
||||
|
||||
type AmountInputProps = {
|
||||
id?: string;
|
||||
inputRef?: MutableRefObject<HTMLInputElement>;
|
||||
inputRef?: Ref<HTMLInputElement>;
|
||||
initialValue: number;
|
||||
zeroSign?: '-' | '+';
|
||||
onChange?: (value: number) => void;
|
||||
@@ -39,8 +39,11 @@ export function AmountInput({
|
||||
let [negative, setNegative] = useState(
|
||||
(initialValue === 0 && zeroSign === '-') || initialValue < 0,
|
||||
);
|
||||
|
||||
let initialValueAbsolute = format(Math.abs(initialValue), 'financial');
|
||||
let [value, setValue] = useState(initialValueAbsolute);
|
||||
useEffect(() => setValue(initialValueAbsolute), [initialValueAbsolute]);
|
||||
|
||||
let buttonRef = useRef();
|
||||
|
||||
function onSwitch() {
|
||||
@@ -64,6 +67,12 @@ export function AmountInput({
|
||||
let ref = useRef<HTMLInputElement>();
|
||||
let mergedRef = useMergedRefs<HTMLInputElement>(inputRef, ref);
|
||||
|
||||
useEffect(() => {
|
||||
if (focused) {
|
||||
ref.current?.focus();
|
||||
}
|
||||
}, [focused]);
|
||||
|
||||
function onInputAmountBlur(e) {
|
||||
fireChange(value, negative);
|
||||
if (!ref.current?.contains(e.relatedTarget)) {
|
||||
|
||||
Reference in New Issue
Block a user