Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2885 - Focus ring getting stuck on last column of /accounts/budgeted #3571

Merged
merged 8 commits into from
Nov 12, 2024
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 @@ -1722,6 +1723,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 @@ -1783,6 +1789,7 @@ function NewTransaction({
style={{ marginRight: 10, padding: '4px 10px' }}
onPress={() => onClose()}
data-testid="cancel-button"
ref={cancelButtonRef}
>
Cancel
</Button>
Expand All @@ -1802,6 +1809,7 @@ function NewTransaction({
style={{ padding: '4px 10px' }}
onPress={onAdd}
data-testid="add-button"
ref={addButtonRef}
>
Add
</Button>
Expand Down Expand Up @@ -2175,10 +2183,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 @@ -2243,8 +2255,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 @@ -2256,6 +2286,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.