Skip to content

Commit 611c41c

Browse files
MelvinBotmkhutornyi
andcommitted
Use skipNextFocusRestore() instead of filtering back button in focusFirstInteractiveElement
Reverts the back-button filtering in focusFirstInteractiveElement and instead calls skipNextFocusRestore() before navigating from participants to the confirm page, matching the approach used in IOURequestStepMerchant. Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
1 parent 9123104 commit 611c41c

3 files changed

Lines changed: 4 additions & 23 deletions

File tree

src/hooks/useDialogContainerFocus/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import FOCUSABLE_SELECTOR from '@libs/focusableSelector';
55
import hasFocusableAttributes from '@libs/focusGuards';
66
import getHadTabNavigation from '@libs/hadTabNavigation';
77
import {Priorities, tryClaim} from '@libs/ScreenFocusArbiter';
8-
import CONST from '@src/CONST';
98
import type UseDialogContainerFocus from './types';
109

1110
function focusFirstInteractiveElement(container: HTMLElement | null): boolean {
1211
if (!getHadTabNavigation() || !container || (document.activeElement && document.activeElement !== document.body)) {
1312
return false;
1413
}
1514
const targets = container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR);
16-
const target = Array.from(targets).find((el) => hasFocusableAttributes(el) && el.id !== CONST.BACK_BUTTON_NATIVE_ID);
15+
const target = Array.from(targets).find(hasFocusableAttributes);
1716
if (!target) {
1817
return false;
1918
}

src/hooks/useParticipantSubmission.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {READ_COMMANDS} from '@libs/API/types';
55
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
66
import HttpUtils from '@libs/HttpUtils';
77
import Navigation from '@libs/Navigation/Navigation';
8+
import {skipNextFocusRestore} from '@libs/NavigationFocusReturn';
89
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
910
import {findSelfDMReportID, generateReportID, isInvoiceRoomWithID} from '@libs/ReportUtils';
1011
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
@@ -364,6 +365,8 @@ function useParticipantSubmission({
364365
: iouConfirmationPageRoute;
365366

366367
KeyboardUtils.dismissKeyboardAndExecute(() => {
368+
// Skip the focus restore so the confirm page doesn't auto-focus the back button.
369+
skipNextFocusRestore();
367370
// If the backTo parameter is set, we should navigate back to the confirmation screen that is already on the stack.
368371
// We wrap navigation in setNavigationActionToMicrotaskQueue so that data loading in Onyx and navigation do not occur simultaneously, which resets the amount to 0.
369372
// More information can be found here: https://github.com/Expensify/App/issues/73728

tests/unit/focusFirstInteractiveElementTest.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -303,27 +303,6 @@ describe('focusFirstInteractiveElement', () => {
303303
expect(buttonSpy).toHaveBeenCalled();
304304
});
305305

306-
it('should skip the back button (BACK_BUTTON_NATIVE_ID) and focus the next element', () => {
307-
const backButton = document.createElement('button');
308-
backButton.id = 'backButton';
309-
const nextButton = document.createElement('button');
310-
const container = createContainer(backButton, nextButton);
311-
const backSpy = jest.spyOn(backButton, 'focus');
312-
const nextSpy = jest.spyOn(nextButton, 'focus');
313-
314-
focusFirstInteractiveElement(container);
315-
expect(backSpy).not.toHaveBeenCalled();
316-
expect(nextSpy).toHaveBeenCalled();
317-
});
318-
319-
it('should return false when the only focusable element is the back button', () => {
320-
const backButton = document.createElement('button');
321-
backButton.id = 'backButton';
322-
const container = createContainer(backButton);
323-
324-
expect(focusFirstInteractiveElement(container)).toBe(false);
325-
});
326-
327306
it('should skip elements inside an [inert] subtree', () => {
328307
const inertWrapper = document.createElement('div');
329308
inertWrapper.setAttribute('inert', '');

0 commit comments

Comments
 (0)