Skip to content

Commit

Permalink
Focus input on negative/positive
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Sep 7, 2023
1 parent 8717eec commit 3b76c9f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/desktop-client/src/components/util/AmountInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
integerToCurrency,
} from 'loot-core/src/shared/util';

import { useMergedRefs } from '../../hooks/useMergedRefs';
import Add from '../../icons/v1/Add';
import Subtract from '../../icons/v1/Subtract';
import Button from '../common/Button';
Expand All @@ -23,8 +24,11 @@ export function AmountInput({
let [negative, setNegative] = useState(initialValue <= 0);
let initialValueAbsolute = integerToCurrency(Math.abs(initialValue || 0));
let [value, setValue] = useState(initialValueAbsolute);
let ref = useRef();
let mergedRef = useMergedRefs(inputRef, ref);

function onSwitch() {
ref.current?.focus();
setNegative(!negative);
fireChange(value, !negative);
}
Expand All @@ -51,7 +55,7 @@ export function AmountInput({
return (
<InputWithContent
id={id}
inputRef={inputRef}
inputRef={mergedRef}
inputMode="decimal"
leftContent={
<Button type="bare" style={{ padding: '0 7px' }} onClick={onSwitch}>
Expand Down

0 comments on commit 3b76c9f

Please sign in to comment.