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 @@ -49,6 +49,7 @@ import {

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 @@ -1670,6 +1671,11 @@ function NewTransaction({
);
const emptyChildTransactions = childTransactions.filter(t => t.amount === 0);

const addRef = useRef(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const addRef = useRef(null);
const addButtonRef = useRef(null);

useProperFocus(addRef, focusedField === 'add');
const cancelRef = useRef(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const cancelRef = useRef(null);
const cancelButtonRef = useRef(null);

useProperFocus(cancelRef, focusedField === 'cancel');

return (
<View
style={{
Expand Down Expand Up @@ -1731,6 +1737,7 @@ function NewTransaction({
style={{ marginRight: 10, padding: '4px 10px' }}
onPress={() => onClose()}
data-testid="cancel-button"
ref={cancelRef}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ref={cancelRef}
ref={cancelButtonRef}

>
Cancel
</Button>
Expand All @@ -1750,6 +1757,7 @@ function NewTransaction({
style={{ padding: '4px 10px' }}
onPress={onAdd}
data-testid="add-button"
ref={addRef}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ref={addRef}
ref={addButtonRef}

>
Add
</Button>
Expand Down Expand Up @@ -2117,10 +2125,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 @@ -2185,8 +2197,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 @@ -2198,6 +2228,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.