-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix: return focus and soft keyboard to description input on iOS after canceling discard modal #97823
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
Open
MelvinBot
wants to merge
7
commits into
main
Choose a base branch
from
claude-iosFocusDescriptionOnCancel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−1
Open
Fix: return focus and soft keyboard to description input on iOS after canceling discard modal #97823
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ba38c3
Fix: return focus/keyboard to description input on iOS after cancelin…
MelvinBot 9d7aa47
Add test pinning focusComposerWithDelay args in Description discard-m…
MelvinBot 23a4845
Fix Oxfmt: reorder imports in IOURequestStepDescriptionTest
MelvinBot 2640b9f
Fix typecheck: correct mock factory signature and drop HOC-provided p…
MelvinBot 095b1f3
Fix ESLint: remove unused rest param from focusComposer mock factory
MelvinBot 5fa7db0
Fix TS2556 in IOURequestStepDescription test by simplifying focusComp…
MelvinBot 7568a65
Merge remote-tracking branch 'origin/main' into claude-iosFocusDescri…
MelvinBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import {act, render} from '@testing-library/react-native'; | ||
|
|
||
| import IOURequestStepDescription from '@pages/iou/request/step/IOURequestStepDescription'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import SCREENS from '@src/SCREENS'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import createMock from '../utils/createMock'; | ||
| import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; | ||
|
|
||
| /** | ||
| * These tests pin the exact arguments passed to `focusComposerWithDelay` from the discard-modal `onCancel` handler | ||
| * in `IOURequestStepDescription`. The fix that requires them (returning focus AND re-requesting the soft keyboard on | ||
| * iOS after canceling the "Discard changes?" modal) cannot be verified manually in dev/simulator, so this assertion | ||
| * is the regression net: it fails loudly if the third `forceKeyboardIfAlreadyFocused` argument is ever trimmed. | ||
| */ | ||
|
|
||
| // Capture the inner focus function so we can assert the exact args the component invokes it with. | ||
| const mockFocusFn = jest.fn(); | ||
| jest.mock('@libs/focusComposerWithDelay', () => ({ | ||
| __esModule: true, | ||
| default: () => mockFocusFn, | ||
| })); | ||
|
|
||
| // Capture the `onCancel` the component wires into the discard-changes hook, without dragging in the real | ||
| // navigation/modal machinery (that flow is covered by tests/unit/hooks/useDiscardChangesConfirmationNative.test.ts). | ||
| let capturedOnCancel: (() => void) | undefined; | ||
| jest.mock('@hooks/useDiscardChangesConfirmation', () => ({ | ||
| __esModule: true, | ||
| default: (options: {onCancel?: () => void}) => { | ||
| capturedOnCancel = options.onCancel; | ||
| return {suppressDiscardPrompt: jest.fn()}; | ||
| }, | ||
| })); | ||
|
|
||
| // The "OrNotFound" HOCs gate rendering on Onyx report/transaction data that is irrelevant to this wiring test. | ||
| // Stub them to pass-through so the real component body runs directly. | ||
| jest.mock('@pages/iou/request/step/withWritableReportOrNotFound', () => (Component: React.ComponentType) => Component); | ||
| jest.mock('@pages/iou/request/step/withFullTransactionOrNotFound', () => (Component: React.ComponentType) => Component); | ||
|
|
||
| // The JSX children are irrelevant here — the `onCancel` closure is created in the component body before render. | ||
| // Stubbing them keeps the render trivial and stable. | ||
| jest.mock('@pages/iou/request/step/StepScreenWrapper', () => () => null); | ||
| jest.mock('@components/Form/FormProvider', () => () => null); | ||
| jest.mock('@components/Form/InputWrapper', () => () => null); | ||
|
|
||
| jest.mock('@hooks/useThemeStyles', () => ({ | ||
| __esModule: true, | ||
| default: () => ({}), | ||
| })); | ||
| jest.mock('@hooks/useLocalize', () => ({ | ||
| __esModule: true, | ||
| default: () => ({translate: (key: string) => key}), | ||
| })); | ||
| jest.mock('@hooks/useAutoFocusInput', () => ({ | ||
| __esModule: true, | ||
| default: () => ({inputCallbackRef: jest.fn(), inputRef: {current: null}}), | ||
| })); | ||
|
|
||
| const ROUTE = createMock<React.ComponentProps<typeof IOURequestStepDescription>['route']>({ | ||
| key: 'Money_Request_Step_Description-test', | ||
| name: SCREENS.MONEY_REQUEST.STEP_DESCRIPTION, | ||
| params: { | ||
| action: CONST.IOU.ACTION.CREATE, | ||
| iouType: CONST.IOU.TYPE.SUBMIT, | ||
| reportID: 'report-1', | ||
| transactionID: 'txn-1', | ||
| }, | ||
| }); | ||
| const NAVIGATION = createMock<React.ComponentProps<typeof IOURequestStepDescription>['navigation']>({}); | ||
|
|
||
| describe('IOURequestStepDescription - discard modal onCancel', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| capturedOnCancel = undefined; | ||
| }); | ||
|
|
||
| it('re-requests the soft keyboard on cancel by forcing focus even when the input is still focused', async () => { | ||
| render( | ||
| <IOURequestStepDescription | ||
| route={ROUTE} | ||
| navigation={NAVIGATION} | ||
| />, | ||
| ); | ||
| // Let the component's useOnyx subscriptions settle so their updates don't fire outside act(). | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // The component must have wired an onCancel handler into the discard-changes hook. | ||
| expect(capturedOnCancel).toBeDefined(); | ||
|
|
||
| act(() => capturedOnCancel?.()); | ||
|
|
||
| // Pins the exact PR change: shouldDelay=true, no forced selection range, forceKeyboardIfAlreadyFocused=true. | ||
| expect(mockFocusFn).toHaveBeenCalledWith(true, undefined, true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡
(true, undefined, true)is unreadable at the call site and has no commentNothing tells a reader what either boolean means, and the
undefinedis a positional hole forforcedSelectionRange. The realistic risk is a future cleanup "simplifying" this back to(true)and silently reintroducing the exact bug this PR fixes, because the diff would look like dead-argument removal.IOURequestStepDistanceOdometer.tsx:547-550already sets the precedent for documenting a focus call whose shape is load-bearing. Match it:This also covers the checklist item the author left unchecked: "I verified that comments were added to code that is not self explanatory". @MelvinBot Let me know your take on this, and apply the change if it makes sense.