Skip to content

fix(amount-input): reliably autofocus the amount field on desktop#2277

Merged
Hugo0 merged 1 commit into
devfrom
fix/amount-input-autofocus
Jun 24, 2026
Merged

fix(amount-input): reliably autofocus the amount field on desktop#2277
Hugo0 merged 1 commit into
devfrom
fix/amount-input-autofocus

Conversation

@Hugo0

@Hugo0 Hugo0 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

The amount input stopped auto-focusing when entering some flows (reported on add money — you have to click the field to start typing). It relied on React's autoFocus prop, which only fires at the exact moment the <input> mounts and silently no-ops when the input mounts after a client-side navigation / step transition (e.g. the add-money amount step). Replaced it with an explicit inputRef.focus() in a useEffect gated on the same desktop-only shouldAutoFocus = deviceType === WEB condition, so focus lands reliably regardless of mount timing.

Risk

  • Low, FE-only, one file. AmountInput is shared (send / withdraw / qr-pay / add-money / request). The change restores the same intent the autoFocus prop had (focus on desktop mount) but reliably — no new behavior.
  • Mobile unchanged: autofocus stays OFF on iOS/Android by design (shouldAutoFocus is false there).
  • Not related to fix(request): show spendable balance incl. card collateral #2266 (balance PR).

QA

Desktop web: open Add money → amount step — the field is focused (blinking caret) without a click. Same for Send, Withdraw, QR pay amount screens. On mobile, the field is NOT auto-focused (unchanged). Full unit suite green.

The amount field stopped auto-focusing when entering some flows (reported on
add money): it used React's `autoFocus` prop, which only fires at the exact
moment the input mounts and silently no-ops when the input mounts after a
client-side navigation / step transition. Replace it with an explicit
inputRef.focus() in a useEffect gated on the same desktop-only condition
(shouldAutoFocus = deviceType === WEB), so focus lands regardless of mount
timing. Mobile is unchanged (autofocus stays off by design). Shared component —
restores focus across send / withdraw / qr-pay / add-money without altering the
mobile path.
@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
peanut-wallet Ready Ready Preview, Comment Jun 24, 2026 9:59pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d80d74ba-0205-4675-bf21-166567cb0708

📥 Commits

Reviewing files that changed from the base of the PR and between 5f37002 and ea33c3f.

📒 Files selected for processing (1)
  • src/components/Global/AmountInput/index.tsx

Walkthrough

AmountInput now triggers autofocus through a mount effect that calls inputRef.current.focus() when enabled, and the input element no longer uses the autoFocus prop.

Changes

Desktop autofocus handling

Layer / File(s) Summary
Mount focus effect
src/components/Global/AmountInput/index.tsx
AmountInput adds a mount useEffect that focuses the input ref when shouldAutoFocus is true, and removes the input's autoFocus prop.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5-15 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing desktop autofocus for the amount input.
Description check ✅ Passed The description matches the changeset and explains the autofocus fix, scope, and behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Code-analysis diff

Painscore total: 5745.31 → 5745.45 (+0.14)
Findings: 0 net (+3 new, -3 resolved)

🆕 New findings (3)

  • critical complexity — src/components/Global/AmountInput/index.tsx — CC 69, MI 59.97, SLOC 176
  • medium high-mdd — src/components/Global/AmountInput/index.tsx:38 — AmountInput: MDD 48.7 (uses across many lines from declarations)
  • medium method-complexity — src/components/Global/AmountInput/index.tsx:38 — CC 17 SLOC 62

✅ Resolved (3)

  • src/components/Global/AmountInput/index.tsx — CC 67, MI 59.66, SLOC 172
  • src/components/Global/AmountInput/index.tsx:38 — AmountInput: MDD 46.2 (uses across many lines from declarations)
  • src/components/Global/AmountInput/index.tsx:38 — CC 17 SLOC 60

@github-actions

Copy link
Copy Markdown
Contributor

🧪 UI test report — ✅ all green

Suites

  • unit: 1556 ran, 0 failed, 0 skipped, 22.8s

📊 Coverage (unit)

metric %
statements 53.4%
branches 36.3%
functions 40.9%
lines 53.3%
⏱ 10 slowest test cases
time test
0.6s src/app/actions/__tests__/api-headers.test.ts › should include Content-Type in updateUserById
0.3s src/components/Card/share-asset/__tests__/shareAssetLayout.test.ts › every stamp stays within canvas at any count
0.2s src/app/actions/__tests__/api-headers-extended.test.ts › should not include apiKey in updateUserById body
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle valid 9-digit US account
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle too long for US account
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle maximum length (17 digits) US account
0.1s src/app/actions/__tests__/api-headers.test.ts › should include Content-Type in createOnrampForGuest
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle unresolvable ENS name
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle valid US account with spaces 2
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle valid German IBAN
📍 Inline annotations are in the **Unit test report** check above. Coverage artifact: `coverage-unit`. Generated by `.github/workflows/tests.yml`.

@Hugo0 Hugo0 marked this pull request as ready for review June 24, 2026 22:01
@Hugo0 Hugo0 merged commit ee360db into dev Jun 24, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant