Skip to content

Commit 3190100

Browse files
committed
Revert "Use skipNextFocusRestore() instead of filtering back button in focusFirstInteractiveElement"
This reverts commit 611c41c.
1 parent 611c41c commit 3190100

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/hooks/useDialogContainerFocus/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ 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';
89
import type UseDialogContainerFocus from './types';
910

1011
function focusFirstInteractiveElement(container: HTMLElement | null): boolean {
1112
if (!getHadTabNavigation() || !container || (document.activeElement && document.activeElement !== document.body)) {
1213
return false;
1314
}
1415
const targets = container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR);
15-
const target = Array.from(targets).find(hasFocusableAttributes);
16+
const target = Array.from(targets).find((el) => hasFocusableAttributes(el) && el.id !== CONST.BACK_BUTTON_NATIVE_ID);
1617
if (!target) {
1718
return false;
1819
}

src/hooks/useParticipantSubmission.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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';
98
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
109
import {findSelfDMReportID, generateReportID, isInvoiceRoomWithID} from '@libs/ReportUtils';
1110
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
@@ -365,8 +364,6 @@ function useParticipantSubmission({
365364
: iouConfirmationPageRoute;
366365

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

tests/unit/focusFirstInteractiveElementTest.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,27 @@ 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+
306327
it('should skip elements inside an [inert] subtree', () => {
307328
const inertWrapper = document.createElement('div');
308329
inertWrapper.setAttribute('inert', '');

0 commit comments

Comments
 (0)