Skip to content

Commit

Permalink
Fixes actualbudget#2885 - Focus ring getting stuck on last column of …
Browse files Browse the repository at this point in the history
…/accounts/budgeted (actualbudget#3571)

* Fixes focus ring getting stuck on last column of /accounts/budgeted screen when creating a new transaction.

* Fix lint problems with the previous commit

* Changed the way the hook is made to the cancel and add button, removing the need to change Button2

* Changed the name of variables as mentioned in PR
  • Loading branch information
The-Firexx authored Nov 12, 2024
1 parent 9e47801 commit d132440
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { useMergedRefs } from '../../hooks/useMergedRefs';
import { usePrevious } from '../../hooks/usePrevious';
import { useProperFocus } from '../../hooks/useProperFocus';
import { useSelectedDispatch, useSelectedItems } from '../../hooks/useSelected';
import { useSplitsExpanded } from '../../hooks/useSplitsExpanded';
import { SvgLeftArrow2, SvgRightArrow2, SvgSplit } from '../../icons/v0';
Expand Down Expand Up @@ -1725,6 +1726,11 @@ function NewTransaction({
);
const emptyChildTransactions = childTransactions.filter(t => t.amount === 0);

const addButtonRef = useRef(null);
useProperFocus(addButtonRef, focusedField === 'add');
const cancelButtonRef = useRef(null);
useProperFocus(cancelButtonRef, focusedField === 'cancel');

return (
<View
style={{
Expand Down Expand Up @@ -1786,6 +1792,7 @@ function NewTransaction({
style={{ marginRight: 10, padding: '4px 10px' }}
onPress={() => onClose()}
data-testid="cancel-button"
ref={cancelButtonRef}
>
Cancel
</Button>
Expand All @@ -1805,6 +1812,7 @@ function NewTransaction({
style={{ padding: '4px 10px' }}
onPress={onAdd}
data-testid="add-button"
ref={addButtonRef}
>
Add
</Button>
Expand Down Expand Up @@ -2178,10 +2186,14 @@ export const TransactionTable = forwardRef((props, ref) => {
}
}, [prevSplitsExpanded.current]);

const newNavigator = useTableNavigator(newTransactions, getFields);
const newNavigator = useTableNavigator(
newTransactions,
getFieldsNewTransaction,
);

const tableNavigator = useTableNavigator(
transactionsWithExpandedSplits,
getFields,
getFieldsTableTransaction,
);
const shouldAdd = useRef(false);
const latestState = useRef({ newTransactions, newNavigator, tableNavigator });
Expand Down Expand Up @@ -2246,8 +2258,26 @@ export const TransactionTable = forwardRef((props, ref) => {
savePending.current = false;
}, [newTransactions, props.transactions]);

function getFields(item) {
let fields = [
function getFieldsNewTransaction(item) {
const fields = [
'select',
'date',
'account',
'payee',
'notes',
'category',
'debit',
'credit',
'cleared',
'cancel',
'add',
];

return getFields(item, fields);
}

function getFieldsTableTransaction(item) {
const fields = [
'select',
'date',
'account',
Expand All @@ -2259,6 +2289,10 @@ export const TransactionTable = forwardRef((props, ref) => {
'cleared',
];

return getFields(item, fields);
}

function getFields(item, fields) {
fields = item.is_child
? ['select', 'payee', 'notes', 'category', 'debit', 'credit']
: fields.filter(
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3571.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [The-Firexx]
---

Fixes focus ring getting "stuck" on last column of /accounts/budgeted screen when creating a new transaction.

0 comments on commit d132440

Please sign in to comment.