Skip to content

A local-first personal finance app

Update @actual-app/components/input to be based on react-aria-components Input component (#4955)

Joel Jeremy Marquez1876ba9fe74c
diff --git a/packages/component-library/src/Input.tsx b/packages/component-library/src/Input.tsx
index e7c73ba28d..4b9d9fad0d 100644
--- a/packages/component-library/src/Input.tsx
+++ b/packages/component-library/src/Input.tsx
@@ -1,16 +1,18 @@
import React, {
- type InputHTMLAttributes,
+ ChangeEvent,
+ ComponentPropsWithRef,
type KeyboardEvent,
- type Ref,
+ type FocusEvent,
} from 'react';
+import { Input as ReactAriaInput } from 'react-aria-components';
import { css, cx } from '@emotion/css';
import { useResponsive } from './hooks/useResponsive';
-import { styles, type CSSProperties } from './styles';
+import { styles } from './styles';
import { theme } from './theme';
-export const defaultInputStyle = {
+export const baseInputStyle = {
outline: 0,
backgroundColor: theme.tableBackground,
color: theme.formInputText,
@@ -20,85 +22,91 @@ export const defaultInputStyle = {
border: '1px solid ' + theme.formInputBorder,
};
-export type InputProps = InputHTMLAttributes<HTMLInputElement> & {
- style?: CSSProperties;
- inputRef?: Ref<HTMLInputElement>;
- onEnter?: (event: KeyboardEvent<HTMLInputElement>) => void;
- onEscape?: (event: KeyboardEvent<HTMLInputElement>) => void;
- onChangeValue?: (newValue: string) => void;
- onUpdate?: (newValue: string) => void;
+const defaultInputClassName = css({
+ ...baseInputStyle,
+ color: theme.formInputText,
+ whiteSpace: 'nowrap',
+ overflow: 'hidden',
+ flexShrink: 0,
+ '&[data-focused]': {
+ border: '1px solid ' + theme.formInputBorderSelected,
+ boxShadow: '0 1px 1px ' + theme.formInputShadowSelected,
+ },
+ '&[data-disabled]': {
+ color: theme.formInputTextPlaceholder,
+ },
+ '::placeholder': { color: theme.formInputTextPlaceholder },
+ ...styles.smallText,
+});
+
+export type InputProps = ComponentPropsWithRef<typeof ReactAriaInput> & {
+ onEnter?: (value: string, event: KeyboardEvent<HTMLInputElement>) => void;
+ onEscape?: (value: string, event: KeyboardEvent<HTMLInputElement>) => void;
+ onChangeValue?: (
+ newValue: string,
+ event: ChangeEvent<HTMLInputElement>,
+ ) => void;
+ onUpdate?: (newValue: string, event: FocusEvent<HTMLInputElement>) => void;
};
export function Input({
- style,
- inputRef,
+ ref,
onEnter,
onEscape,
onChangeValue,
onUpdate,
className,
- ...nativeProps
+ ...props
}: InputProps) {
return (
- <input
- ref={inputRef}
- className={cx(
- css(
- defaultInputStyle,
- {
- color: nativeProps.disabled
- ? theme.formInputTextPlaceholder
- : theme.formInputText,
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- flexShrink: 0,
- ':focus': {
- border: '1px solid ' + theme.formInputBorderSelected,
- boxShadow: '0 1px 1px ' + theme.formInputShadowSelected,
- },
- '::placeholder': { color: theme.formInputTextPlaceholder },
- },
- styles.smallText,
- style,
- ),
- className,
- )}
- {...nativeProps}
- onKeyDown={e => {
- nativeProps.onKeyDown?.(e);
+ <ReactAriaInput
+ ref={ref}
+ className={
+ typeof className === 'function'
+ ? renderProps => cx(defaultInputClassName, className(renderProps))
+ : cx(defaultInputClassName, className)
+ }
+ {...props}
+ onKeyUp={e => {
+ props.onKeyUp?.(e);
if (e.key === 'Enter' && onEnter) {
- onEnter(e);
+ onEnter(e.currentTarget.value, e);
}
if (e.key === 'Escape' && onEscape) {
- onEscape(e);
+ onEscape(e.currentTarget.value, e);
}
}}
onBlur={e => {
- onUpdate?.(e.target.value);
- nativeProps.onBlur?.(e);
+ onUpdate?.(e.currentTarget.value, e);
+ props.onBlur?.(e);
}}
onChange={e => {
- onChangeValue?.(e.target.value);
- nativeProps.onChange?.(e);
+ onChangeValue?.(e.currentTarget.value, e);
+ props.onChange?.(e);
}}
/>
);
}
-export function BigInput(props: InputProps) {
+const defaultBigInputClassName = css({
+ padding: 10,
+ fontSize: 15,
+ border: 'none',
+ ...styles.shadow,
+ '&[data-focused]': { border: 'none', ...styles.shadow },
+});
+
+export function BigInput({ className, ...props }: InputProps) {
return (
<Input
{...props}
- style={{
- padding: 10,
- fontSize: 15,
- border: 'none',
- ...styles.shadow,
- ':focus': { border: 'none', ...styles.shadow },
- ...props.style,
- }}
+ className={
+ typeof className === 'function'
+ ? renderProps => cx(defaultBigInputClassName, className(renderProps))
+ : cx(defaultBigInputClassName, className)
+ }
/>
);
}
diff --git a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-1-chromium-linux.png b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-1-chromium-linux.png
index 17880346c5..2645ca7388 100644
Binary files a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-1-chromium-linux.png and b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-3-chromium-linux.png b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-3-chromium-linux.png
index 082a0870f8..a6ae84fc03 100644
Binary files a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-3-chromium-linux.png and b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-creates-a-transfer-test-transaction-3-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/EditablePageHeaderTitle.tsx b/packages/desktop-client/src/components/EditablePageHeaderTitle.tsx
index 1c3d408581..e2d541e447 100644
--- a/packages/desktop-client/src/components/EditablePageHeaderTitle.tsx
+++ b/packages/desktop-client/src/components/EditablePageHeaderTitle.tsx
@@ -35,8 +35,8 @@ export function EditablePageHeaderTitle({
<InitialFocus>
<Input
defaultValue={title}
- onEnter={e => onSaveValue(e.currentTarget.value)}
- onBlur={e => onSaveValue(e.target.value)}
+ onEnter={onSaveValue}
+ onUpdate={onSaveValue}
onEscape={() => setIsEditing(false)}
style={{
fontSize: 25,
diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsx
index ac70c442b1..561a0c9f43 100644
--- a/packages/desktop-client/src/components/accounts/Header.tsx
+++ b/packages/desktop-client/src/components/accounts/Header.tsx
@@ -1,6 +1,5 @@
import React, {
type ComponentProps,
- Fragment,
type ReactNode,
useRef,
useState,
@@ -355,6 +354,9 @@ export function AccountHeader({
value={search}
onChange={onSearch}
inputRef={searchInput}
+ // Remove marginRight magically being added by Stack...
+ // We need to refactor the Stack component
+ style={{ marginRight: 0 }}
/>
{workingHard ? (
<View>
@@ -598,12 +600,12 @@ function AccountNameField({
if (editingName) {
return (
- <Fragment>
+ <>
<InitialFocus>
<Input
defaultValue={accountName}
- onEnter={e => handleSave(e.currentTarget.value)}
- onBlur={e => handleSave(e.target.value)}
+ onEnter={handleSave}
+ onUpdate={handleSave}
onEscape={() => setEditingName(false)}
style={{
fontSize: 25,
@@ -620,7 +622,7 @@ function AccountNameField({
{saveNameError && (
<View style={{ color: theme.warningText }}>{saveNameError}</View>
)}
- </Fragment>
+ </>
);
} else {
if (isNameEditable) {
diff --git a/packages/desktop-client/src/components/accounts/Reconcile.tsx b/packages/desktop-client/src/components/accounts/Reconcile.tsx
index d20e0c7842..9886fb177f 100644
--- a/packages/desktop-client/src/components/accounts/Reconcile.tsx
+++ b/packages/desktop-client/src/components/accounts/Reconcile.tsx
@@ -1,4 +1,5 @@
-import React, { useState } from 'react';
+import React, { type FormEvent, useState } from 'react';
+import { Form } from 'react-aria-components';
import { Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
@@ -138,7 +139,9 @@ export function ReconcileMenu({
const locale = useLocale();
const [inputValue, setInputValue] = useState<string | null>(null);
- function onSubmit() {
+ function onSubmit(e: FormEvent<HTMLFormElement>) {
+ e.preventDefault();
+
if (inputValue === '') {
return;
}
@@ -151,36 +154,37 @@ export function ReconcileMenu({
}
return (
- <View style={{ padding: '5px 8px' }}>
- <Text>
- <Trans>
- Enter the current balance of your bank account that you want to
- reconcile with:
- </Trans>
- </Text>
- {clearedBalance != null && (
- <InitialFocus>
- <Input
- defaultValue={format(clearedBalance, 'financial')}
- onChangeValue={setInputValue}
- style={{ margin: '7px 0' }}
- onEnter={onSubmit}
- />
- </InitialFocus>
- )}
- <Text style={{ color: theme.pageTextSubdued, paddingBottom: 6 }}>
- {account?.last_reconciled
- ? t('Reconciled {{ relativeTimeAgo }}', {
- relativeTimeAgo: tsToRelativeTime(
- account.last_reconciled,
- locale,
- ),
- })
- : t('Not yet reconciled')}
- </Text>
- <Button variant="primary" onPress={onSubmit}>
- <Trans>Reconcile</Trans>
- </Button>
- </View>
+ <Form onSubmit={onSubmit}>
+ <View style={{ padding: '5px 8px' }}>
+ <Text>
+ <Trans>
+ Enter the current balance of your bank account that you want to
+ reconcile with:
+ </Trans>
+ </Text>
+ {clearedBalance != null && (
+ <InitialFocus>
+ <Input
+ defaultValue={format(clearedBalance, 'financial')}
+ onChangeValue={setInputValue}
+ style={{ margin: '7px 0' }}
+ />
+ </InitialFocus>
+ )}
+ <Text style={{ color: theme.pageTextSubdued, paddingBottom: 6 }}>
+ {account?.last_reconciled
+ ? t('Reconciled {{ relativeTimeAgo }}', {
+ relativeTimeAgo: tsToRelativeTime(
+ account.last_reconciled,
+ locale,
+ ),
+ })
+ : t('Not yet reconciled')}
+ </Text>
+ <Button type="submit" variant="primary">
+ <Trans>Reconcile</Trans>
+ </Button>
+ </View>
+ </Form>
);
}
diff --git a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx
index d4d2fe1d96..f146bfd494 100644
--- a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx
@@ -1,6 +1,5 @@
// @ts-strict-ignore
import React, {
- type ChangeEvent,
type ComponentProps,
type HTMLProps,
type KeyboardEvent,
@@ -31,9 +30,7 @@ type CommonAutocompleteProps<T extends Item> = {
embedded?: boolean;
containerProps?: HTMLProps<HTMLDivElement>;
labelProps?: { id?: string };
- inputProps?: Omit<ComponentProps<typeof Input>, 'onChange'> & {
- onChange?: (value: string) => void;
- };
+ inputProps?: ComponentProps<typeof Input>;
suggestions?: T[];
renderInput?: (props: ComponentProps<typeof Input>) => ReactNode;
renderItems?: (
@@ -461,7 +458,7 @@ function SingleAutocomplete<T extends Item>({
<View ref={triggerRef} style={{ flexShrink: 0 }}>
{renderInput(
getInputProps({
- inputRef,
+ ref: inputRef,
...inputProps,
onFocus: e => {
inputProps.onFocus?.(e);
@@ -568,10 +565,6 @@ function SingleAutocomplete<T extends Item>({
}
}
},
- onChange: (e: ChangeEvent<HTMLInputElement>) => {
- const { onChange } = inputProps || {};
- onChange?.(e.target.value);
- },
}),
)}
</View>
@@ -649,6 +642,13 @@ function MultiItem({ name, onRemove }: MultiItemProps) {
);
}
+const defaultMultiAutocompleteInputClassName = css({
+ flex: 1,
+ minWidth: 30,
+ border: 0,
+ '&[data-focused]': { border: 0, boxShadow: 'none' },
+});
+
type MultiAutocompleteProps<T extends Item> = CommonAutocompleteProps<T> & {
type: 'multi';
onSelect: (ids: T['id'][], id?: T['id']) => void;
@@ -704,7 +704,7 @@ function MultiAutocomplete<T extends Item>({
onSelect={onAddItem}
highlightFirst
strict={strict}
- renderInput={inputProps => (
+ renderInput={({ className: inputClassName, ...inputProps }) => (
<View
style={{
display: 'flex',
@@ -734,7 +734,7 @@ function MultiAutocomplete<T extends Item>({
})}
<Input
{...inputProps}
- inputRef={inputRef}
+ ref={inputRef}
onKeyDown={e => onKeyDown(e, inputProps.onKeyDown)}
onFocus={e => {
setFocused(true);
@@ -744,13 +744,15 @@ function MultiAutocomplete<T extends Item>({
setFocused(false);
inputProps.onBlur(e);
}}
- style={{
- flex: 1,
- minWidth: 30,
- border: 0,
- ':focus': { border: 0, boxShadow: 'none' },
- ...inputProps.style,
- }}
+ className={
+ typeof inputClassName === 'function'
+ ? renderProps =>
+ cx(
+ defaultMultiAutocompleteInputClassName,
+ inputClassName(renderProps),
+ )
+ : cx(defaultMultiAutocompleteInputClassName, inputClassName)
+ }
/>
</View>
)}
diff --git a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
index 25eb9e6fb0..76c2463a90 100644
--- a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
@@ -368,7 +368,7 @@ export function PayeeAutocomplete({
setPayeeFieldFocused(false);
},
onFocus: () => setPayeeFieldFocused(true),
- onChange: setRawPayee,
+ onChangeValue: setRawPayee,
}}
onUpdate={(id, inputValue) => onUpdate?.(id, makeNew(id, inputValue))}
onSelect={handleSelect}
diff --git a/packages/desktop-client/src/components/budget/envelope/CoverMenu.tsx b/packages/desktop-client/src/components/budget/envelope/CoverMenu.tsx
index b4c5cb5f30..93bf9d9a62 100644
--- a/packages/desktop-client/src/components/budget/envelope/CoverMenu.tsx
+++ b/packages/desktop-client/src/components/budget/envelope/CoverMenu.tsx
@@ -1,4 +1,5 @@
import React, { useMemo, useState } from 'react';
+import { Form } from 'react-aria-components';
import { Trans, useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
@@ -41,7 +42,7 @@ export function CoverMenu({
: categoryGroups;
}, [categoryId, showToBeBudgeted, originalCategoryGroups]);
- function submit() {
+ function _onSubmit() {
if (fromCategoryId) {
onSubmit(fromCategoryId);
}
@@ -49,45 +50,53 @@ export function CoverMenu({
}
return (
- <View style={{ padding: 10 }}>
- <View style={{ marginBottom: 5 }}>
- <Trans>Cover from a category:</Trans>
- </View>
+ <Form
+ onSubmit={e => {
+ e.preventDefault();
+ _onSubmit();
+ }}
+ >
+ <View style={{ padding: 10 }}>
+ <View style={{ marginBottom: 5 }}>
+ <Trans>Cover from a category:</Trans>
+ </View>
- <InitialFocus<HTMLInputElement>>
- {node => (
- <CategoryAutocomplete
- categoryGroups={filteredCategoryGroups}
- value={null}
- openOnFocus={true}
- onSelect={(id: string | undefined) => setFromCategoryId(id || null)}
- inputProps={{
- inputRef: node,
- onEnter: event => !event.defaultPrevented && submit(),
- placeholder: t('(none)'),
- }}
- showHiddenCategories={false}
- />
- )}
- </InitialFocus>
+ <InitialFocus<HTMLInputElement>>
+ {node => (
+ <CategoryAutocomplete
+ categoryGroups={filteredCategoryGroups}
+ value={null}
+ openOnFocus={true}
+ onSelect={(id: string | undefined) =>
+ setFromCategoryId(id || null)
+ }
+ inputProps={{
+ ref: node,
+ placeholder: t('(none)'),
+ }}
+ showHiddenCategories={false}
+ />
+ )}
+ </InitialFocus>
- <View
- style={{
- alignItems: 'flex-end',
- marginTop: 10,
- }}
- >
- <Button
- variant="primary"
+ <View
style={{
- fontSize: 12,
- paddingTop: 3,
+ alignItems: 'flex-end',
+ marginTop: 10,
}}
- onPress={submit}
>
- <Trans>Transfer</Trans>
- </Button>
+ <Button
+ type="submit"
+ variant="primary"
+ style={{
+ fontSize: 12,
+ paddingTop: 3,
+ }}
+ >
+ <Trans>Transfer</Trans>
+ </Button>
+ </View>
</View>
- </View>
+ </Form>
);
}
diff --git a/packages/desktop-client/src/components/budget/envelope/HoldMenu.tsx b/packages/desktop-client/src/components/budget/envelope/HoldMenu.tsx
index 7d761856a6..98fdc1c61e 100644
--- a/packages/desktop-client/src/components/budget/envelope/HoldMenu.tsx
+++ b/packages/desktop-client/src/components/budget/envelope/HoldMenu.tsx
@@ -1,4 +1,5 @@
-import React, { useState, type ChangeEvent } from 'react';
+import React, { useState } from 'react';
+import { Form } from 'react-aria-components';
import { Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
@@ -22,7 +23,7 @@ export function HoldMenu({ onSubmit, onClose }: HoldMenuProps) {
setAmount(integerToCurrency(Math.max(value || 0, 0)));
});
- function submit(newAmount: string) {
+ function _onSubmit(newAmount: string) {
const parsedAmount = evalArithmetic(newAmount);
if (parsedAmount) {
onSubmit(amountToInteger(parsedAmount));
@@ -36,39 +37,40 @@ export function HoldMenu({ onSubmit, onClose }: HoldMenuProps) {
}
return (
- <View style={{ padding: 10 }}>
- <View style={{ marginBottom: 5 }}>
- <Trans>Hold this amount:</Trans>
- </View>
- <View>
- <InitialFocus>
- <Input
- value={amount}
- onChange={(e: ChangeEvent<HTMLInputElement>) =>
- setAmount(e.target.value)
- }
- onEnter={() => submit(amount)}
- />
- </InitialFocus>
- </View>
- <View
- style={{
- alignItems: 'flex-end',
- marginTop: 10,
- }}
- >
- <Button
- variant="primary"
+ <Form
+ onSubmit={e => {
+ e.preventDefault();
+ _onSubmit(amount);
+ }}
+ >
+ <View style={{ padding: 10 }}>
+ <View style={{ marginBottom: 5 }}>
+ <Trans>Hold this amount:</Trans>
+ </View>
+ <View>
+ <InitialFocus>
+ <Input value={amount} onChangeValue={setAmount} />
+ </InitialFocus>
+ </View>
+ <View
style={{
- fontSize: 12,
- paddingTop: 3,
- paddingBottom: 3,
+ alignItems: 'flex-end',
+ marginTop: 10,
}}
- onPress={() => submit(amount)}
>
- <Trans>Hold</Trans>
- </Button>
+ <Button
+ type="submit"
+ variant="primary"
+ style={{
+ fontSize: 12,
+ paddingTop: 3,
+ paddingBottom: 3,
+ }}
+ >
+ <Trans>Hold</Trans>
+ </Button>
+ </View>
</View>
- </View>
+ </Form>
);
}
diff --git a/packages/desktop-client/src/components/budget/envelope/TransferMenu.tsx b/packages/desktop-client/src/components/budget/envelope/TransferMenu.tsx
index 9652e50330..b1988da15c 100644
--- a/packages/desktop-client/src/components/budget/envelope/TransferMenu.tsx
+++ b/packages/desktop-client/src/components/budget/envelope/TransferMenu.tsx
@@ -1,4 +1,5 @@
import React, { useMemo, useState } from 'react';
+import { Form } from 'react-aria-components';
import { Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
@@ -57,52 +58,53 @@ export function TransferMenu({
};
return (
- <View style={{ padding: 10 }}>
- <View style={{ marginBottom: 5 }}>
- <Trans>Transfer this amount:</Trans>
- </View>
- <View>
- <InitialFocus>
- <Input
- defaultValue={_initialAmount}
- onUpdate={value => setAmount(value)}
- onEnter={() => _onSubmit(amount, toCategoryId)}
- />
- </InitialFocus>
- </View>
- <View style={{ margin: '10px 0 5px 0' }}>To:</View>
+ <Form
+ onSubmit={e => {
+ e.preventDefault();
+ _onSubmit(amount, toCategoryId);
+ }}
+ >
+ <View style={{ padding: 10 }}>
+ <View style={{ marginBottom: 5 }}>
+ <Trans>Transfer this amount:</Trans>
+ </View>
+ <View>
+ <InitialFocus>
+ <Input defaultValue={_initialAmount} onUpdate={setAmount} />
+ </InitialFocus>
+ </View>
+ <View style={{ margin: '10px 0 5px 0' }}>To:</View>
- <CategoryAutocomplete
- categoryGroups={filteredCategoryGroups}
- value={null}
- openOnFocus={true}
- onSelect={(id: string | undefined) => setToCategoryId(id || null)}
- inputProps={{
- onEnter: event =>
- !event.defaultPrevented && _onSubmit(amount, toCategoryId),
- placeholder: '(none)',
- }}
- showHiddenCategories={true}
- />
+ <CategoryAutocomplete
+ categoryGroups={filteredCategoryGroups}
+ value={null}
+ openOnFocus={true}
+ onSelect={(id: string | undefined) => setToCategoryId(id || null)}
+ inputProps={{
+ placeholder: '(none)',
+ }}
+ showHiddenCategories={true}
+ />
- <View
- style={{
- alignItems: 'flex-end',
- marginTop: 10,
- }}
- >
- <Button
- variant="primary"
+ <View
style={{
- fontSize: 12,
- paddingTop: 3,
- paddingBottom: 3,
+ alignItems: 'flex-end',
+ marginTop: 10,
}}
- onPress={() => _onSubmit(amount, toCategoryId)}
>
- <Trans>Transfer</Trans>
- </Button>
+ <Button
+ type="submit"
+ variant="primary"
+ style={{
+ fontSize: 12,
+ paddingTop: 3,
+ paddingBottom: 3,
+ }}
+ >
+ <Trans>Transfer</Trans>
+ </Button>
+ </View>
</View>
- </View>
+ </Form>
);
}
diff --git a/packages/desktop-client/src/components/common/Modal.tsx b/packages/desktop-client/src/components/common/Modal.tsx
index aaec2e0f5b..2bde54b2bd 100644
--- a/packages/desktop-client/src/components/common/Modal.tsx
+++ b/packages/desktop-client/src/components/common/Modal.tsx
@@ -413,7 +413,7 @@ export function ModalTitle({
return isEditing ? (
<Input
- inputRef={inputRef}
+ ref={inputRef}
style={{
fontSize: 25,
fontWeight: 700,
@@ -422,11 +422,9 @@ export function ModalTitle({
}}
defaultValue={title}
onUpdate={_onTitleUpdate}
- onKeyDown={e => {
- if (e.key === 'Enter') {
- e.preventDefault();
- _onTitleUpdate?.(e.currentTarget.value);
- }
+ onEnter={(value, e) => {
+ e.preventDefault();
+ _onTitleUpdate?.(value);
}}
/>
) : (
diff --git a/packages/desktop-client/src/components/common/Search.tsx b/packages/desktop-client/src/components/common/Search.tsx
index e56ef5c78a..9373c79361 100644
--- a/packages/desktop-client/src/components/common/Search.tsx
+++ b/packages/desktop-client/src/components/common/Search.tsx
@@ -3,10 +3,11 @@ import { useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { SvgRemove, SvgSearchAlternate } from '@actual-app/components/icons/v2';
-import { defaultInputStyle, Input } from '@actual-app/components/input';
+import { baseInputStyle, Input } from '@actual-app/components/input';
import { type CSSProperties } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { css } from '@emotion/css';
type SearchProps = {
inputRef?: Ref<HTMLInputElement>;
@@ -16,7 +17,7 @@ type SearchProps = {
isInModal?: boolean;
width?: number | '100%';
height?: number;
- inputStyle?: CSSProperties;
+ style?: CSSProperties;
};
export function Search({
@@ -27,7 +28,7 @@ export function Search({
isInModal = false,
width = 250,
height,
- inputStyle = {},
+ style,
}: SearchProps) {
const { t } = useTranslation();
@@ -38,7 +39,7 @@ export function Search({
return (
<View
style={{
- ...defaultInputStyle,
+ ...baseInputStyle,
padding: 0,
flexDirection: 'row',
alignItems: 'center',
@@ -48,8 +49,7 @@ export function Search({
flex: '',
borderColor: isInModal ? undefined : 'transparent',
backgroundColor: isInModal ? undefined : theme.formInputBackground,
- ...inputStyle,
-
+ ...style,
...(focused && {
boxShadow: '0 0 0 1px ' + theme.formInputShadowSelected,
...(isInModal
@@ -70,20 +70,18 @@ export function Search({
/>
<Input
- inputRef={inputRef}
+ ref={inputRef}
value={value}
placeholder={placeholder}
- onKeyDown={e => {
- if (e.key === 'Escape') onChange('');
- }}
+ onEscape={() => onChange('')}
onChangeValue={onChange}
- style={{
+ className={css({
width: '100%',
'::placeholder': {
color: theme.formInputTextPlaceholder,
transition: 'color .25s',
},
- ':focus': isInModal
+ '&[data-focused]': isInModal
? {}
: {
'::placeholder': {
@@ -91,13 +89,13 @@ export function Search({
},
},
flex: 1,
- '&, &:focus, &:hover': {
+ '&, &[data-focused], &[data-hovered]': {
border: 0,
backgroundColor: 'transparent',
boxShadow: 'none',
color: 'inherit',
},
- }}
+ })}
onFocus={() => {
setFocused(true);
}}
diff --git a/packages/desktop-client/src/components/filters/FiltersMenu.jsx b/packages/desktop-client/src/components/filters/FiltersMenu.jsx
index e204842f7b..100e88ca3d 100644
--- a/packages/desktop-client/src/components/filters/FiltersMenu.jsx
+++ b/packages/desktop-client/src/components/filters/FiltersMenu.jsx
@@ -220,7 +220,7 @@ function ConfigureField({
>
{type !== 'boolean' && (
<GenericInput
- inputRef={inputRef}
+ ref={inputRef}
field={field}
subfield={subfield}
type={
diff --git a/packages/desktop-client/src/components/filters/NameFilter.tsx b/packages/desktop-client/src/components/filters/NameFilter.tsx
index 6c180cec8d..29b335bac1 100644
--- a/packages/desktop-client/src/components/filters/NameFilter.tsx
+++ b/packages/desktop-client/src/components/filters/NameFilter.tsx
@@ -57,7 +57,7 @@ export function NameFilter({
/>
<Input
id="name-field"
- inputRef={inputRef}
+ ref={inputRef}
defaultValue={name || ''}
onChangeValue={setName}
/>
diff --git a/packages/desktop-client/src/components/manager/ConfigServer.tsx b/packages/desktop-client/src/components/manager/ConfigServer.tsx
index cf280a728c..b632280347 100644
--- a/packages/desktop-client/src/components/manager/ConfigServer.tsx
+++ b/packages/desktop-client/src/components/manager/ConfigServer.tsx
@@ -8,6 +8,7 @@ import { Label } from '@actual-app/components/label';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { css } from '@emotion/css';
import {
isNonProductionEnvironment,
@@ -156,12 +157,12 @@ export function ElectronServerConfig({
value="localhost"
disabled
type="text"
- style={{
+ className={css({
'&::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
WebkitAppearance: 'none',
margin: 0,
},
- }}
+ })}
/>
</View>
@@ -175,14 +176,14 @@ export function ElectronServerConfig({
value={String(electronServerPort)}
aria-label={t('Port')}
type="number"
- style={{
+ className={css({
'&::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
WebkitAppearance: 'none',
margin: 0,
},
width: '7ch',
textAlign: 'center',
- }}
+ })}
autoFocus={true}
maxLength={5}
onChange={event =>
diff --git a/packages/desktop-client/src/components/manager/subscribe/ConfirmPasswordForm.tsx b/packages/desktop-client/src/components/manager/subscribe/ConfirmPasswordForm.tsx
index 49affc542f..f43b90c3f9 100644
--- a/packages/desktop-client/src/components/manager/subscribe/ConfirmPasswordForm.tsx
+++ b/packages/desktop-client/src/components/manager/subscribe/ConfirmPasswordForm.tsx
@@ -6,6 +6,7 @@ import { ButtonWithLoading } from '@actual-app/components/button';
import { BigInput } from '@actual-app/components/input';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { css } from '@emotion/css';
type ConfirmPasswordFormProps = {
buttons: ReactNode;
@@ -137,12 +138,12 @@ export function ConfirmOldPasswordForm({
setPassword(e.target.value)
}
onEnter={onSubmit}
- style={{
+ className={css({
borderColor: theme.buttonMenuBorder,
borderWidth: 1,
borderStyle: 'solid',
- ':focus': {},
- }}
+ '&[data-focused]': {},
+ })}
/>
<View
diff --git a/packages/desktop-client/src/components/manager/subscribe/Login.tsx b/packages/desktop-client/src/components/manager/subscribe/Login.tsx
index 6dc609fed6..a2494cab99 100644
--- a/packages/desktop-client/src/components/manager/subscribe/Login.tsx
+++ b/packages/desktop-client/src/components/manager/subscribe/Login.tsx
@@ -68,7 +68,7 @@ function PasswordLogin({ setError, dispatch }) {
autoFocus={true}
placeholder={t('Password')}
type="password"
- onChangeValue={newValue => setPassword(newValue)}
+ onChangeValue={setPassword}
style={{ flex: 1 }}
onEnter={onSubmitPassword}
/>
diff --git a/packages/desktop-client/src/components/mobile/MobileForms.tsx b/packages/desktop-client/src/components/mobile/MobileForms.tsx
index ca67c7e769..756c462017 100644
--- a/packages/desktop-client/src/components/mobile/MobileForms.tsx
+++ b/packages/desktop-client/src/components/mobile/MobileForms.tsx
@@ -52,7 +52,7 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(
({ disabled, style, onUpdate, ...props }, ref) => {
return (
<Input
- inputRef={ref}
+ ref={ref}
autoCorrect="false"
autoCapitalize="none"
disabled={disabled}
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx
index cd67eead2e..fd3eeded99 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx
@@ -54,7 +54,7 @@ function TransactionSearchInput({
placeholder={placeholder}
width="100%"
height={styles.mobileMinHeight}
- inputStyle={{
+ style={{
backgroundColor: theme.tableBackground,
borderColor: theme.formInputBorder,
}}
diff --git a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx
index b23bff3200..5a0e8f6dfe 100644
--- a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx
+++ b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx
@@ -202,7 +202,7 @@ export function CreateEncryptionKeyModal({
width: isNarrowWidth ? '100%' : '50%',
height: isNarrowWidth ? styles.mobileMinHeight : undefined,
}}
- onChange={e => setPassword(e.target.value)}
+ onChangeValue={setPassword}
/>
</InitialFocus>
<Text style={{ marginTop: 5 }}>
diff --git a/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsx b/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsx
index d61814daad..91722ff147 100644
--- a/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsx
+++ b/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsx
@@ -92,9 +92,9 @@ export function CreateLocalAccountModal() {
<Input
name="name"
value={name}
- onChange={event => setName(event.target.value)}
- onBlur={event => {
- const name = event.target.value.trim();
+ onChangeValue={setName}
+ onUpdate={value => {
+ const name = value.trim();
validateAndSetName(name);
}}
style={{ flex: 1 }}
@@ -167,9 +167,9 @@ export function CreateLocalAccountModal() {
name="balance"
inputMode="decimal"
value={balance}
- onChange={event => setBalance(event.target.value)}
- onBlur={event => {
- const balance = event.target.value.trim();
+ onChangeValue={setBalance}
+ onUpdate={value => {
+ const balance = value.trim();
setBalance(balance);
if (validateBalance(balance) && balanceError) {
setBalanceError(false);
diff --git a/packages/desktop-client/src/components/modals/EditFieldModal.tsx b/packages/desktop-client/src/components/modals/EditFieldModal.tsx
index 678cf374a2..8fc15b60de 100644
--- a/packages/desktop-client/src/components/modals/EditFieldModal.tsx
+++ b/packages/desktop-client/src/components/modals/EditFieldModal.tsx
@@ -203,10 +203,10 @@ export function EditFieldModal({
</Button>
</View>
<Input
- inputRef={noteInputRef}
+ ref={noteInputRef}
autoFocus
- onEnter={e => {
- onSelectNote(e.currentTarget.value, noteAmend);
+ onEnter={value => {
+ onSelectNote(value, noteAmend);
close();
}}
style={inputStyle}
@@ -219,8 +219,8 @@ export function EditFieldModal({
label = t('Amount');
editor = ({ close }) => (
<Input
- onEnter={e => {
- onSelect(e.currentTarget.value);
+ onEnter={value => {
+ onSelect(value);
close();
}}
style={inputStyle}
diff --git a/packages/desktop-client/src/components/modals/EditUser.tsx b/packages/desktop-client/src/components/modals/EditUser.tsx
index e3b97fdcc0..7c5ca969c4 100644
--- a/packages/desktop-client/src/components/modals/EditUser.tsx
+++ b/packages/desktop-client/src/components/modals/EditUser.tsx
@@ -205,7 +205,7 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {
<Input
id="name-field"
value={userName}
- onChangeValue={text => setUserName(text)}
+ onChangeValue={setUserName}
style={{
borderColor: theme.buttonMenuBorder,
}}
@@ -261,7 +261,7 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {
<Input
id="displayname-field"
value={displayName}
- onChangeValue={text => setDisplayName(text)}
+ onChangeValue={setDisplayName}
placeholder={t('(Optional)')}
style={{
borderColor: theme.buttonMenuBorder,
diff --git a/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx b/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx
index e664667285..52fb609ca6 100644
--- a/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx
+++ b/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx
@@ -143,7 +143,7 @@ export function FixEncryptionKeyModal({
width: isNarrowWidth ? '100%' : '50%',
height: isNarrowWidth ? styles.mobileMinHeight : undefined,
}}
- onChange={e => setPassword(e.target.value)}
+ onChangeValue={setPassword}
/>
</InitialFocus>
<Text style={{ marginTop: 5 }}>
diff --git a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx
index cdc1dd7cb0..120eae22ee 100644
--- a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx
+++ b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx
@@ -150,8 +150,8 @@ export function DuplicateFileModal({
value={newName}
aria-label={t('New Budget Name')}
aria-invalid={nameError ? 'true' : 'false'}
- onChange={event => setNewName(event.target.value)}
- onBlur={event => validateAndSetName(event.target.value)}
+ onChangeValue={setNewName}
+ onUpdate={validateAndSetName}
style={{ flex: 1 }}
/>
</InitialFocus>
diff --git a/packages/desktop-client/src/components/reports/ReportCardName.tsx b/packages/desktop-client/src/components/reports/ReportCardName.tsx
index d741e9e527..bad6685f07 100644
--- a/packages/desktop-client/src/components/reports/ReportCardName.tsx
+++ b/packages/desktop-client/src/components/reports/ReportCardName.tsx
@@ -26,7 +26,7 @@ export const ReportCardName = ({
<Input
className={NON_DRAGGABLE_AREA_CLASS_NAME}
defaultValue={name}
- onEnter={e => onChange(e.currentTarget.value)}
+ onEnter={onChange}
onUpdate={onChange}
onEscape={onClose}
style={{
diff --git a/packages/desktop-client/src/components/reports/SaveReportChoose.tsx b/packages/desktop-client/src/components/reports/SaveReportChoose.tsx
index 7fd1084d3b..889592cf0a 100644
--- a/packages/desktop-client/src/components/reports/SaveReportChoose.tsx
+++ b/packages/desktop-client/src/components/reports/SaveReportChoose.tsx
@@ -47,7 +47,7 @@ export function SaveReportChoose({ onApply }: SaveReportChooseProps) {
<View style={{ flex: 1 }} />
</View>
<GenericInput
- inputRef={inputRef}
+ ref={inputRef}
field="report"
subfield={null}
type="saved"
diff --git a/packages/desktop-client/src/components/reports/SaveReportName.tsx b/packages/desktop-client/src/components/reports/SaveReportName.tsx
index 9df0b05931..542cbdf23e 100644
--- a/packages/desktop-client/src/components/reports/SaveReportName.tsx
+++ b/packages/desktop-client/src/components/reports/SaveReportName.tsx
@@ -73,7 +73,7 @@ export function SaveReportName({
<Input
value={name}
id="name-field"
- inputRef={inputRef}
+ ref={inputRef}
onChangeValue={setName}
style={{ marginTop: 10 }}
/>
diff --git a/packages/desktop-client/src/components/schedules/CustomUpcomingLength.tsx b/packages/desktop-client/src/components/schedules/CustomUpcomingLength.tsx
index 294c7c4464..c21ec9d8e6 100644
--- a/packages/desktop-client/src/components/schedules/CustomUpcomingLength.tsx
+++ b/packages/desktop-client/src/components/schedules/CustomUpcomingLength.tsx
@@ -45,7 +45,7 @@ export function CustomUpcomingLength({
style={{ width: 40 }}
type="number"
min={1}
- onChange={e => setNumValue(parseInt(e.target.value))}
+ onChangeValue={value => setNumValue(parseInt(value))}
defaultValue={numValue || 1}
/>
<Select
diff --git a/packages/desktop-client/src/components/select/DateSelect.tsx b/packages/desktop-client/src/components/select/DateSelect.tsx
index e4808dd6a5..4df326633a 100644
--- a/packages/desktop-client/src/components/select/DateSelect.tsx
+++ b/packages/desktop-client/src/components/select/DateSelect.tsx
@@ -390,7 +390,7 @@ export function DateSelect({
<Input
id={id}
{...inputProps}
- inputRef={inputRef}
+ ref={inputRef}
value={value}
onPointerUp={() => {
if (!embedded) {
diff --git a/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx b/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
index 05405a7f94..c95e0f39c5 100644
--- a/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
+++ b/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
@@ -457,7 +457,7 @@ function RecurringScheduleTooltip({
style={{ width: 40 }}
type="number"
min={1}
- onChange={e => updateField('endOccurrences', e.target.value)}
+ onChangeValue={value => updateField('endOccurrences', value)}
defaultValue={config.endOccurrences || 1}
/>
{config.endOccurrences === '1' ? (
@@ -491,7 +491,7 @@ function RecurringScheduleTooltip({
style={{ width: 40 }}
type="number"
min={1}
- onChange={e => updateField('interval', e.target.value)}
+ onChangeValue={value => updateField('interval', value)}
defaultValue={config.interval || 1}
/>
<Select
diff --git a/packages/desktop-client/src/components/sidebar/Account.tsx b/packages/desktop-client/src/components/sidebar/Account.tsx
index e775331210..ea8de87de8 100644
--- a/packages/desktop-client/src/components/sidebar/Account.tsx
+++ b/packages/desktop-client/src/components/sidebar/Account.tsx
@@ -194,9 +194,7 @@ export function Account<FieldName extends SheetFields<'account'>>({
width: '100%',
}}
onBlur={() => setIsEditing(false)}
- onEnter={e => {
- const inputEl = e.target as HTMLInputElement;
- const newAccountName = inputEl.value;
+ onEnter={newAccountName => {
if (newAccountName.trim() !== '') {
dispatch(
updateAccount({
diff --git a/packages/desktop-client/src/components/sidebar/BudgetName.tsx b/packages/desktop-client/src/components/sidebar/BudgetName.tsx
index a386254a98..dda2c43e70 100644
--- a/packages/desktop-client/src/components/sidebar/BudgetName.tsx
+++ b/packages/desktop-client/src/components/sidebar/BudgetName.tsx
@@ -97,9 +97,7 @@ function EditableBudgetName() {
fontWeight: 500,
}}
defaultValue={budgetName}
- onEnter={e => {
- const inputEl = e.target as HTMLInputElement;
- const newBudgetName = inputEl.value;
+ onEnter={newBudgetName => {
if (newBudgetName.trim() !== '') {
setBudgetNamePref(newBudgetName);
setEditing(false);
diff --git a/packages/desktop-client/src/components/table.tsx b/packages/desktop-client/src/components/table.tsx
index 0b120bd36f..2fa97721b2 100644
--- a/packages/desktop-client/src/components/table.tsx
+++ b/packages/desktop-client/src/components/table.tsx
@@ -313,8 +313,12 @@ const readonlyInputStyle = {
'::selection': { backgroundColor: theme.formInputTextReadOnlySelection },
};
-type InputValueProps = Omit<ComponentProps<typeof Input>, 'value'> & {
+type InputValueProps = Omit<
+ ComponentProps<typeof Input>,
+ 'value' | 'onUpdate'
+> & {
value?: string;
+ onUpdate?: (newValue: string) => void;
};
function InputValue({
@@ -344,15 +348,17 @@ function InputValue({
e.stopPropagation();
}
- if (e.key === 'Escape') {
- if (value !== defaultValue) {
- setValue(defaultValue);
- }
- } else if (shouldSaveFromKey(e)) {
+ if (shouldSaveFromKey(e)) {
onUpdate?.(value);
}
}
+ function onEscape() {
+ if (value !== defaultValue) {
+ setValue(defaultValue);
+ }
+ }
+
const ops = ['+', '-', '*', '/', '^'];
function valueIsASingleOperator(text) {
@@ -371,10 +377,11 @@ function InputValue({
<Input
{...props}
value={value}
- onChangeValue={text => setValue_(text)}
+ onChangeValue={setValue_}
onBlur={onBlur_}
onUpdate={onUpdate}
onKeyDown={onKeyDown}
+ onEscape={onEscape}
style={{
...inputCellStyle,
...(props.readOnly ? readonlyInputStyle : null),
diff --git a/packages/desktop-client/src/components/util/AmountInput.tsx b/packages/desktop-client/src/components/util/AmountInput.tsx
index c845758141..ff01744d48 100644
--- a/packages/desktop-client/src/components/util/AmountInput.tsx
+++ b/packages/desktop-client/src/components/util/AmountInput.tsx
@@ -12,9 +12,10 @@ import { useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { SvgAdd, SvgSubtract } from '@actual-app/components/icons/v1';
-import { defaultInputStyle, Input } from '@actual-app/components/input';
+import { baseInputStyle, Input } from '@actual-app/components/input';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { css, cx } from '@emotion/css';
import { evalArithmetic } from 'loot-core/shared/arithmetic';
import { amountToInteger, appendDecimals } from 'loot-core/shared/util';
@@ -36,6 +37,7 @@ type AmountInputProps = {
onUpdate?: (amount: number) => void;
style?: CSSProperties;
inputStyle?: CSSProperties;
+ inputClassName?: string;
focused?: boolean;
disabled?: boolean;
autoDecimals?: boolean;
@@ -53,6 +55,7 @@ export function AmountInput({
onEnter,
style,
inputStyle,
+ inputClassName,
focused,
disabled = false,
autoDecimals = false,
@@ -120,7 +123,7 @@ export function AmountInput({
return (
<View
style={{
- ...defaultInputStyle,
+ ...baseInputStyle,
padding: 0,
flexDirection: 'row',
flex: 1,
@@ -149,21 +152,24 @@ export function AmountInput({
<Input
id={id}
- inputRef={mergedRef}
+ ref={mergedRef}
inputMode="decimal"
value={value}
disabled={disabled}
- style={{
- width: '100%',
- ...inputStyle,
- flex: 1,
- '&, &:focus, &:hover': {
- border: 0,
- backgroundColor: 'transparent',
- boxShadow: 'none',
- color: 'inherit',
- },
- }}
+ style={inputStyle}
+ className={cx(
+ css({
+ width: '100%',
+ flex: 1,
+ '&, &[data-focused], &[data-hovered]': {
+ border: 0,
+ backgroundColor: 'transparent',
+ boxShadow: 'none',
+ color: 'inherit',
+ },
+ }),
+ inputClassName,
+ )}
onFocus={e => {
setIsFocused(true);
onFocus?.(e);
@@ -172,13 +178,11 @@ export function AmountInput({
setIsFocused(false);
onInputAmountBlur(e);
}}
- onKeyUp={e => {
- if (e.key === 'Enter') {
- const amount = getAmount();
- fireUpdate(amount);
- }
+ onEnter={(_, e) => {
+ onEnter?.(e);
+ const amount = getAmount();
+ fireUpdate(amount);
}}
- onEnter={onEnter}
onChangeValue={onInputTextChange}
/>
</View>
diff --git a/packages/desktop-client/src/components/util/GenericInput.jsx b/packages/desktop-client/src/components/util/GenericInput.jsx
index 8fa73442b1..cd7028c827 100644
--- a/packages/desktop-client/src/components/util/GenericInput.jsx
+++ b/packages/desktop-client/src/components/util/GenericInput.jsx
@@ -32,7 +32,7 @@ export function GenericInput({
numberFormatType = undefined,
multi,
value,
- inputRef,
+ ref,
style,
onChange,
op = undefined,
@@ -48,7 +48,7 @@ export function GenericInput({
case 'currency':
return (
<AmountInput
- inputRef={inputRef}
+ inputRef={ref}
value={amountToInteger(value)}
onUpdate={v => onChange(integerToAmount(v))}
/>
@@ -56,7 +56,7 @@ export function GenericInput({
case 'percentage':
return (
<PercentInput
- inputRef={inputRef}
+ inputRef={ref}
value={value}
onUpdatePercent={onChange}
/>
@@ -64,11 +64,11 @@ export function GenericInput({
default:
return (
<Input
- inputRef={inputRef}
+ ref={ref}
defaultValue={value || ''}
placeholder={t('nothing')}
- onEnter={e => onChange(e.target.value)}
- onBlur={e => onChange(e.target.value)}
+ onEnter={onChange}
+ onUpdate={onChange}
/>
);
}
@@ -97,7 +97,7 @@ export function GenericInput({
value={value}
onSelect={onChange}
inputProps={{
- inputRef,
+ ref,
...(showPlaceholder ? { placeholder: t('nothing') } : null),
}}
/>
@@ -118,7 +118,7 @@ export function GenericInput({
openOnFocus={true}
onSelect={onChange}
inputProps={{
- inputRef,
+ ref,
...(showPlaceholder ? { placeholder: t('nothing') } : null),
}}
/>
@@ -137,7 +137,7 @@ export function GenericInput({
onSelect={onChange}
showHiddenCategories={false}
inputProps={{
- inputRef,
+ ref,
...(showPlaceholder ? { placeholder: t('nothing') } : null),
}}
/>
@@ -159,7 +159,7 @@ export function GenericInput({
openOnFocus={true}
onSelect={onChange}
inputProps={{
- inputRef,
+ ref,
...(showPlaceholder ? { placeholder: t('nothing') } : null),
}}
/>
@@ -174,7 +174,7 @@ export function GenericInput({
openOnFocus={true}
onSelect={onChange}
inputProps={{
- inputRef,
+ ref,
...(showPlaceholder ? { placeholder: t('nothing') } : null),
}}
/>
@@ -190,11 +190,11 @@ export function GenericInput({
case 'month':
content = (
<Input
- inputRef={inputRef}
+ ref={ref}
defaultValue={value || ''}
placeholder={getMonthYearFormat(dateFormat).toLowerCase()}
- onEnter={e => onChange(e.target.value)}
- onBlur={e => onChange(e.target.value)}
+ onEnter={onChange}
+ onUpdate={onChange}
/>
);
break;
@@ -202,11 +202,11 @@ export function GenericInput({
case 'year':
content = (
<Input
- inputRef={inputRef}
+ ref={ref}
defaultValue={value || ''}
placeholder="yyyy"
- onEnter={e => onChange(e.target.value)}
- onBlur={e => onChange(e.target.value)}
+ onEnter={onChange}
+ onUpdate={onChange}
/>
);
break;
@@ -226,7 +226,7 @@ export function GenericInput({
value={value}
dateFormat={dateFormat}
openOnFocus={false}
- inputRef={inputRef}
+ inputRef={ref}
inputProps={{ placeholder: dateFormat.toLowerCase() }}
onSelect={onChange}
/>
@@ -253,7 +253,7 @@ export function GenericInput({
type={autocompleteType}
suggestions={[]}
value={value}
- inputProps={{ inputRef }}
+ inputProps={{ ref }}
onSelect={onChange}
/>
);
@@ -262,11 +262,11 @@ export function GenericInput({
} else {
content = (
<Input
- inputRef={inputRef}
+ ref={ref}
defaultValue={value || ''}
placeholder={t('nothing')}
- onEnter={e => onChange(e.target.value)}
- onBlur={e => onChange(e.target.value)}
+ onEnter={onChange}
+ onUpdate={onChange}
/>
);
}
diff --git a/packages/desktop-client/src/components/util/PercentInput.tsx b/packages/desktop-client/src/components/util/PercentInput.tsx
index dcfd135576..dd8cbfad57 100644
--- a/packages/desktop-client/src/components/util/PercentInput.tsx
+++ b/packages/desktop-client/src/components/util/PercentInput.tsx
@@ -106,16 +106,12 @@ export function PercentInput({
return (
<Input
id={id}
- inputRef={mergedRef}
+ ref={mergedRef}
inputMode="decimal"
value={value}
disabled={disabled}
style={{ flex: 1, alignItems: 'stretch', ...style }}
- onKeyUp={e => {
- if (e.key === 'Enter') {
- fireUpdate();
- }
- }}
+ onEnter={fireUpdate}
onChangeValue={onInputTextChange}
onBlur={onInputAmountBlur}
onFocus={onFocus}
diff --git a/upcoming-release-notes/4955.md b/upcoming-release-notes/4955.md
new file mode 100644
index 0000000000..b6eee33c21
--- /dev/null
+++ b/upcoming-release-notes/4955.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [joel-jeremy]
+---
+
+Update @actual-app/components/input to be based on react-aria-components Input component.