Skip to content

A local-first personal finance app

Automatically focus inputs, or the primary button, in modals. (#2974)

Robert Dyer5e3485a8e299
diff --git a/packages/desktop-client/src/components/accounts/Account.jsx b/packages/desktop-client/src/components/accounts/Account.jsx
index 06fddb35e6..3153fd749f 100644
--- a/packages/desktop-client/src/components/accounts/Account.jsx
+++ b/packages/desktop-client/src/components/accounts/Account.jsx
@@ -75,7 +75,12 @@ function EmptyMessage({ onAdd }) {
manage it locally yourself.
</Text>
- <Button variant="primary" style={{ marginTop: 20 }} onPress={onAdd}>
+ <Button
+ variant="primary"
+ style={{ marginTop: 20 }}
+ autoFocus
+ onPress={onAdd}
+ >
Add account
</Button>
diff --git a/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx b/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx
index 046f047eb5..e8812ecada 100644
--- a/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx
+++ b/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx
@@ -140,6 +140,7 @@ export function AccountSyncCheck() {
<Button onPress={unlink}>Unlink</Button>
<Button
variant="primary"
+ autoFocus
onPress={reauth}
style={{ marginLeft: 5 }}
>
diff --git a/packages/desktop-client/src/components/accounts/Reconcile.jsx b/packages/desktop-client/src/components/accounts/Reconcile.jsx
index ab7127858e..5ebcd31fa7 100644
--- a/packages/desktop-client/src/components/accounts/Reconcile.jsx
+++ b/packages/desktop-client/src/components/accounts/Reconcile.jsx
@@ -78,7 +78,7 @@ export function ReconcilingMessage({
</View>
)}
<View style={{ marginLeft: 15 }}>
- <Button variant="primary" onPress={onDone}>
+ <Button variant="primary" autoFocus onPress={onDone}>
Done Reconciling
</Button>
</View>
diff --git a/packages/desktop-client/src/components/manager/ImportActual.tsx b/packages/desktop-client/src/components/manager/ImportActual.tsx
index 360f7d7a41..78305fdeb3 100644
--- a/packages/desktop-client/src/components/manager/ImportActual.tsx
+++ b/packages/desktop-client/src/components/manager/ImportActual.tsx
@@ -84,6 +84,7 @@ export function ImportActual({ modalProps }: ImportProps) {
<View style={{ alignSelf: 'center' }}>
<ButtonWithLoading
variant="primary"
+ autoFocus
isLoading={importing}
onPress={onImport}
>
diff --git a/packages/desktop-client/src/components/manager/ImportYNAB4.tsx b/packages/desktop-client/src/components/manager/ImportYNAB4.tsx
index e145977c86..b0a8478bae 100644
--- a/packages/desktop-client/src/components/manager/ImportYNAB4.tsx
+++ b/packages/desktop-client/src/components/manager/ImportYNAB4.tsx
@@ -73,6 +73,7 @@ export function ImportYNAB4({ modalProps }: ImportProps) {
<View>
<ButtonWithLoading
variant="primary"
+ autoFocus
isLoading={importing}
onPress={onImport}
>
diff --git a/packages/desktop-client/src/components/manager/ImportYNAB5.tsx b/packages/desktop-client/src/components/manager/ImportYNAB5.tsx
index 3876f337a5..5771e99c99 100644
--- a/packages/desktop-client/src/components/manager/ImportYNAB5.tsx
+++ b/packages/desktop-client/src/components/manager/ImportYNAB5.tsx
@@ -83,6 +83,7 @@ export function ImportYNAB5({ modalProps }: ImportProps) {
<View>
<ButtonWithLoading
variant="primary"
+ autoFocus
isLoading={importing}
onPress={onImport}
>
diff --git a/packages/desktop-client/src/components/manager/WelcomeScreen.tsx b/packages/desktop-client/src/components/manager/WelcomeScreen.tsx
index 8dcc9f4f3a..71fda245e0 100644
--- a/packages/desktop-client/src/components/manager/WelcomeScreen.tsx
+++ b/packages/desktop-client/src/components/manager/WelcomeScreen.tsx
@@ -90,7 +90,7 @@ export function WelcomeScreen() {
<Button onPress={() => createBudget({ testMode: true })}>
{t('View demo')}
</Button>
- <Button variant="primary" onPress={() => createBudget()}>
+ <Button variant="primary" autoFocus onPress={() => createBudget()}>
{t('Start fresh')}
</Button>
</View>
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
index f80218f6bf..3cb7db7644 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
@@ -460,7 +460,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
const { editingField, onRequestActiveEdit, onClearActiveEdit } =
useSingleActiveEditForm();
- const [totalAmountFocused, setTotalAmountFocused] = useState(false);
+ const [totalAmountFocused, setTotalAmountFocused] = useState(true);
const childTransactionElementRefMap = useRef({});
const payeesById = useMemo(() => groupById(payees), [payees]);
diff --git a/packages/desktop-client/src/components/modals/CloseAccountModal.tsx b/packages/desktop-client/src/components/modals/CloseAccountModal.tsx
index c1668a7010..c51ec6dbaa 100644
--- a/packages/desktop-client/src/components/modals/CloseAccountModal.tsx
+++ b/packages/desktop-client/src/components/modals/CloseAccountModal.tsx
@@ -151,6 +151,7 @@ export function CloseAccountModal({
value={transferAccountId}
inputProps={{
placeholder: 'Select account...',
+ autoFocus: true,
...(isNarrowWidth && {
value: transferAccount?.name || '',
style: {
diff --git a/packages/desktop-client/src/components/modals/ConfirmCategoryDelete.tsx b/packages/desktop-client/src/components/modals/ConfirmCategoryDelete.tsx
index 7713a6a09f..d1191938f4 100644
--- a/packages/desktop-client/src/components/modals/ConfirmCategoryDelete.tsx
+++ b/packages/desktop-client/src/components/modals/ConfirmCategoryDelete.tsx
@@ -67,7 +67,7 @@ export function ConfirmCategoryDelete({
{group ? (
<Block>
Categories in the group <strong>{group.name}</strong> are used
- by existing transaction
+ by existing transactions
{!isIncome &&
' or it has a positive leftover balance currently'}
. <strong>Are you sure you want to delete it?</strong> If so,
@@ -115,6 +115,7 @@ export function ConfirmCategoryDelete({
}))
}
value={transferCategory}
+ focused={true}
inputProps={{
placeholder: 'Select category...',
}}
diff --git a/packages/desktop-client/src/components/modals/ConfirmTransactionDelete.tsx b/packages/desktop-client/src/components/modals/ConfirmTransactionDelete.tsx
index 26f2ecaf23..7c1b43ef83 100644
--- a/packages/desktop-client/src/components/modals/ConfirmTransactionDelete.tsx
+++ b/packages/desktop-client/src/components/modals/ConfirmTransactionDelete.tsx
@@ -3,6 +3,7 @@ import React from 'react';
import { useResponsive } from '../../ResponsiveProvider';
import { styles } from '../../style';
import { Button } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal2';
import { Paragraph } from '../common/Paragraph';
import { View } from '../common/View';
@@ -48,16 +49,18 @@ export function ConfirmTransactionDelete({
>
Cancel
</Button>
- <Button
- variant="primary"
- style={narrowButtonStyle}
- onPress={() => {
- onConfirm();
- close();
- }}
- >
- Delete
- </Button>
+ <InitialFocus>
+ <Button
+ variant="primary"
+ style={narrowButtonStyle}
+ onPress={() => {
+ onConfirm();
+ close();
+ }}
+ >
+ Delete
+ </Button>
+ </InitialFocus>
</View>
</View>
</>
diff --git a/packages/desktop-client/src/components/modals/ConfirmTransactionEdit.tsx b/packages/desktop-client/src/components/modals/ConfirmTransactionEdit.tsx
index 6b445bda66..4d45685914 100644
--- a/packages/desktop-client/src/components/modals/ConfirmTransactionEdit.tsx
+++ b/packages/desktop-client/src/components/modals/ConfirmTransactionEdit.tsx
@@ -3,6 +3,7 @@ import React from 'react';
import { Block } from '../common/Block';
import { Button } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal2';
import { View } from '../common/View';
@@ -88,16 +89,18 @@ export function ConfirmTransactionEdit({
>
Cancel
</Button>
- <Button
- aria-label="Confirm"
- variant="primary"
- onPress={() => {
- close();
- onConfirm();
- }}
- >
- Confirm
- </Button>
+ <InitialFocus>
+ <Button
+ aria-label="Confirm"
+ variant="primary"
+ onPress={() => {
+ close();
+ onConfirm();
+ }}
+ >
+ Confirm
+ </Button>
+ </InitialFocus>
</View>
</View>
</View>
diff --git a/packages/desktop-client/src/components/modals/ConfirmUnlinkAccount.tsx b/packages/desktop-client/src/components/modals/ConfirmUnlinkAccount.tsx
index e3d5fb5359..6a51ded8ba 100644
--- a/packages/desktop-client/src/components/modals/ConfirmUnlinkAccount.tsx
+++ b/packages/desktop-client/src/components/modals/ConfirmUnlinkAccount.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import { Button } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal2';
import { Paragraph } from '../common/Paragraph';
import { View } from '../common/View';
@@ -44,15 +45,17 @@ export function ConfirmUnlinkAccount({
<Button style={{ marginRight: 10 }} onPress={close}>
Cancel
</Button>
- <Button
- variant="primary"
- onPress={() => {
- onUnlink();
- close();
- }}
- >
- Unlink
- </Button>
+ <InitialFocus>
+ <Button
+ variant="primary"
+ onPress={() => {
+ onUnlink();
+ close();
+ }}
+ >
+ Unlink
+ </Button>
+ </InitialFocus>
</View>
</View>
</>
diff --git a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx b/packages/desktop-client/src/components/modals/CreateAccountModal.tsx
index c23e67aaf2..ed88da037a 100644
--- a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx
+++ b/packages/desktop-client/src/components/modals/CreateAccountModal.tsx
@@ -12,6 +12,7 @@ import { type SyncServerStatus } from '../../hooks/useSyncServerStatus';
import { SvgDotsHorizontalTriple } from '../../icons/v1';
import { theme } from '../../style';
import { Button, ButtonWithLoading } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Link } from '../common/Link';
import { Menu } from '../common/Menu';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal2';
@@ -186,17 +187,19 @@ export function CreateAccountModal({
<View style={{ maxWidth: 500, gap: 30, color: theme.pageText }}>
{upgradingAccountId == null && (
<View style={{ gap: 10 }}>
- <Button
- variant="primary"
- style={{
- padding: '10px 0',
- fontSize: 15,
- fontWeight: 600,
- }}
- onPress={onCreateLocalAccount}
- >
- Create local account
- </Button>
+ <InitialFocus>
+ <Button
+ variant="primary"
+ style={{
+ padding: '10px 0',
+ fontSize: 15,
+ fontWeight: 600,
+ }}
+ onPress={onCreateLocalAccount}
+ >
+ Create local account
+ </Button>
+ </InitialFocus>
<View style={{ lineHeight: '1.4em', fontSize: 15 }}>
<Text>
<strong>Create a local account</strong> if you want to add
diff --git a/packages/desktop-client/src/components/modals/GoCardlessExternalMsg.tsx b/packages/desktop-client/src/components/modals/GoCardlessExternalMsg.tsx
index 2dbbc049ee..ef3bef944b 100644
--- a/packages/desktop-client/src/components/modals/GoCardlessExternalMsg.tsx
+++ b/packages/desktop-client/src/components/modals/GoCardlessExternalMsg.tsx
@@ -206,6 +206,7 @@ export function GoCardlessExternalMsg({
<View style={{ flexDirection: 'row', gap: 10, alignItems: 'center' }}>
<Button
variant="primary"
+ autoFocus
style={{
padding: '10px 0',
fontSize: 15,
@@ -272,6 +273,7 @@ export function GoCardlessExternalMsg({
) : success ? (
<Button
variant="primary"
+ autoFocus
style={{
padding: '10px 0',
fontSize: 15,
diff --git a/packages/desktop-client/src/components/modals/GoCardlessInitialise.tsx b/packages/desktop-client/src/components/modals/GoCardlessInitialise.tsx
index fc91a66a1a..6906b26c83 100644
--- a/packages/desktop-client/src/components/modals/GoCardlessInitialise.tsx
+++ b/packages/desktop-client/src/components/modals/GoCardlessInitialise.tsx
@@ -5,6 +5,7 @@ import { send } from 'loot-core/src/platform/client/fetch';
import { Error } from '../alerts';
import { ButtonWithLoading } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Input } from '../common/Input';
import { Link } from '../common/Link';
import {
@@ -78,15 +79,17 @@ export const GoCardlessInitialise = ({
<FormField>
<FormLabel title="Secret ID:" htmlFor="secret-id-field" />
- <Input
- id="secret-id-field"
- type="password"
- value={secretId}
- onChangeValue={value => {
- setSecretId(value);
- setIsValid(true);
- }}
- />
+ <InitialFocus>
+ <Input
+ id="secret-id-field"
+ type="password"
+ value={secretId}
+ onChangeValue={value => {
+ setSecretId(value);
+ setIsValid(true);
+ }}
+ />
+ </InitialFocus>
</FormField>
<FormField>
diff --git a/packages/desktop-client/src/components/modals/ImportTransactions.jsx b/packages/desktop-client/src/components/modals/ImportTransactions.jsx
index 88ffb47885..d3f281a59f 100644
--- a/packages/desktop-client/src/components/modals/ImportTransactions.jsx
+++ b/packages/desktop-client/src/components/modals/ImportTransactions.jsx
@@ -1719,6 +1719,7 @@ export function ImportTransactions({ options }) {
>
<ButtonWithLoading
variant="primary"
+ autoFocus
isDisabled={
transactions?.filter(trans => !trans.isMatchedTransaction)
.length === 0
diff --git a/packages/desktop-client/src/components/modals/MergeUnusedPayees.jsx b/packages/desktop-client/src/components/modals/MergeUnusedPayees.jsx
index 2a82568695..0b236b5982 100644
--- a/packages/desktop-client/src/components/modals/MergeUnusedPayees.jsx
+++ b/packages/desktop-client/src/components/modals/MergeUnusedPayees.jsx
@@ -151,6 +151,7 @@ export function MergeUnusedPayees({ payeeIds, targetPayeeId }) {
<ModalButtons style={{ marginTop: 20 }} focusButton>
<Button
variant="primary"
+ autoFocus
style={{ marginRight: 10 }}
onPress={() => {
onMerge();
diff --git a/packages/desktop-client/src/components/modals/SimpleFinInitialise.tsx b/packages/desktop-client/src/components/modals/SimpleFinInitialise.tsx
index 21613af5c1..f6587c7269 100644
--- a/packages/desktop-client/src/components/modals/SimpleFinInitialise.tsx
+++ b/packages/desktop-client/src/components/modals/SimpleFinInitialise.tsx
@@ -88,6 +88,7 @@ export const SimpleFinInitialise = ({
<ModalButtons>
<ButtonWithLoading
variant="primary"
+ autoFocus
isLoading={isLoading}
onPress={() => {
onSubmit(close);
diff --git a/packages/desktop-client/src/components/reports/SaveReportDelete.tsx b/packages/desktop-client/src/components/reports/SaveReportDelete.tsx
index 7a8da58a5b..436b3ef95f 100644
--- a/packages/desktop-client/src/components/reports/SaveReportDelete.tsx
+++ b/packages/desktop-client/src/components/reports/SaveReportDelete.tsx
@@ -21,7 +21,7 @@ export function SaveReportDelete({
<>
<View style={{ align: 'center' }}>
<Text style={{ color: theme.errorText, marginBottom: 5 }}>
- Do you want to delete report:
+ Are you sure you want to delete report:
</Text>
<View>{name}</View>
</View>
@@ -33,7 +33,7 @@ export function SaveReportDelete({
style={{ marginTop: 15 }}
>
<View style={{ flex: 1 }} />
- <Button variant="primary" onPress={onDelete}>
+ <Button variant="primary" autoFocus onPress={onDelete}>
Yes
</Button>
<Button variant="primary" onPress={onClose}>
diff --git a/packages/desktop-client/src/components/schedules/PostsOfflineNotification.jsx b/packages/desktop-client/src/components/schedules/PostsOfflineNotification.jsx
index b19c0dc9e5..29ad0f5da3 100644
--- a/packages/desktop-client/src/components/schedules/PostsOfflineNotification.jsx
+++ b/packages/desktop-client/src/components/schedules/PostsOfflineNotification.jsx
@@ -81,6 +81,7 @@ export function PostsOfflineNotification() {
<Button onPress={close}>Decide later</Button>
<Button
variant="primary"
+ autoFocus
onPress={() => {
onPost();
close();
diff --git a/packages/desktop-client/src/components/schedules/ScheduleDetails.jsx b/packages/desktop-client/src/components/schedules/ScheduleDetails.jsx
index a91aeb3b6d..67900bf27b 100644
--- a/packages/desktop-client/src/components/schedules/ScheduleDetails.jsx
+++ b/packages/desktop-client/src/components/schedules/ScheduleDetails.jsx
@@ -18,6 +18,7 @@ import { theme } from '../../style';
import { AccountAutocomplete } from '../autocomplete/AccountAutocomplete';
import { PayeeAutocomplete } from '../autocomplete/PayeeAutocomplete';
import { Button } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal2';
import { Stack } from '../common/Stack';
import { Text } from '../common/Text';
@@ -462,15 +463,17 @@ export function ScheduleDetails({ id, transaction }) {
<Stack direction="row" style={{ marginTop: 10 }}>
<FormField style={{ flex: 1 }}>
<FormLabel title="Schedule Name" htmlFor="name-field" />
- <GenericInput
- field="string"
- type="string"
- value={state.fields.name}
- multi={false}
- onChange={e => {
- dispatch({ type: 'set-field', field: 'name', value: e });
- }}
- />
+ <InitialFocus>
+ <GenericInput
+ field="string"
+ type="string"
+ value={state.fields.name}
+ multi={false}
+ onChange={e => {
+ dispatch({ type: 'set-field', field: 'name', value: e });
+ }}
+ />
+ </InitialFocus>
</FormField>
</Stack>
<Stack direction="row" style={{ marginTop: 20 }}>
diff --git a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx b/packages/desktop-client/src/components/schedules/ScheduleLink.tsx
index 74d22edd7b..15b3409a75 100644
--- a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx
+++ b/packages/desktop-client/src/components/schedules/ScheduleLink.tsx
@@ -13,6 +13,7 @@ import {
import { SvgAdd } from '../../icons/v0';
import { Button } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal2';
import { Search } from '../common/Search';
import { Text } from '../common/Text';
@@ -93,14 +94,16 @@ export function ScheduleLink({
: `this transaction belongs`}{' '}
to:
</Text>
- <Search
- inputRef={searchInput}
- isInModal
- width={300}
- placeholder="Filter schedules…"
- value={filter}
- onChange={setFilter}
- />
+ <InitialFocus>
+ <Search
+ inputRef={searchInput}
+ isInModal
+ width={300}
+ placeholder="Filter schedules…"
+ value={filter}
+ onChange={setFilter}
+ />
+ </InitialFocus>
{ids.length === 1 && (
<Button
variant="primary"
diff --git a/packages/desktop-client/src/components/select/RecurringSchedulePicker.jsx b/packages/desktop-client/src/components/select/RecurringSchedulePicker.jsx
index 20244423f9..036b875c88 100644
--- a/packages/desktop-client/src/components/select/RecurringSchedulePicker.jsx
+++ b/packages/desktop-client/src/components/select/RecurringSchedulePicker.jsx
@@ -8,6 +8,7 @@ import { useDateFormat } from '../../hooks/useDateFormat';
import { SvgAdd, SvgSubtract } from '../../icons/v0';
import { theme } from '../../style';
import { Button } from '../common/Button2';
+import { InitialFocus } from '../common/InitialFocus';
import { Input } from '../common/Input';
import { Menu } from '../common/Menu';
import { Popover } from '../common/Popover';
@@ -310,14 +311,16 @@ function RecurringScheduleTooltip({ config: currentConfig, onClose, onSave }) {
<>
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
<label htmlFor="start">From</label>
- <DateSelect
- id="start"
- inputProps={{ placeholder: 'Start Date' }}
- value={config.start}
- onSelect={value => updateField('start', value)}
- containerProps={{ style: { width: 100 } }}
- dateFormat={dateFormat}
- />
+ <InitialFocus>
+ <DateSelect
+ id="start"
+ inputProps={{ placeholder: 'Start Date' }}
+ value={config.start}
+ onSelect={value => updateField('start', value)}
+ containerProps={{ style: { width: 100 } }}
+ dateFormat={dateFormat}
+ />
+ </InitialFocus>
<Select
id="repeat_end_dropdown"
options={[
diff --git a/upcoming-release-notes/2974.md b/upcoming-release-notes/2974.md
new file mode 100644
index 0000000000..ec64722203
--- /dev/null
+++ b/upcoming-release-notes/2974.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [psybers]
+---
+
+Fix: Automatically focus inputs, or the primary button, in modals.