Skip to content

fix(swap): auto-focus input field when swap view opens - #5619

Merged
svenvoskamp merged 1 commit into
chore/khizr-fixesfrom
chore/khizr-fixes-REOWN-3541
Apr 13, 2026
Merged

fix(swap): auto-focus input field when swap view opens#5619
svenvoskamp merged 1 commit into
chore/khizr-fixesfrom
chore/khizr-fixes-REOWN-3541

Conversation

@Khizr97

@Khizr97 Khizr97 commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Auto-focuses the source token input field when the swap view opens so users can immediately start typing (REOWN-3541).

Technical Report

Problem

When the user opens the swap page, the input field is not active — they have to manually click on it before typing an amount. This adds an unnecessary interaction step.

Root Cause Analysis

The w3m-swap-input component had no mechanism to auto-focus the input element on mount. The swap view renders two instances of w3m-swap-input (source token and destination token), and neither received focus automatically.

Approach & Reasoning

Added autoFocus boolean property to w3m-swap-input:

  • New @Property({ type: Boolean }) public autoFocus = false — defaults to false so existing usages are unaffected
  • New firstUpdated() lifecycle hook that queries the shadow DOM for the input element and calls .focus() when autoFocus is true

Why firstUpdated() and not connectedCallback():
firstUpdated() runs after the first render when the shadow DOM is fully constructed. connectedCallback() fires before the first render — the input element doesn't exist yet. firstUpdated() is the correct Lit lifecycle for DOM-dependent initialization.

Why firstUpdated() and not updated():
Focus should only be set once on initial mount, not on every re-render. firstUpdated() runs exactly once per element lifecycle. If the swap view re-renders without destroying the component, focus won't be re-stolen.

Only source token gets focus:
In w3m-swap-view, the attribute is set as ?autoFocus=${target === 'sourceToken'}. The destination token input is disabled/read-only (shows calculated output), so focusing it would be useless.

Optional chaining on querySelector result:
input?.focus() safely handles the (unlikely) case where the input element isn't found in the shadow DOM.

Files Changed

  • packages/scaffold-ui/src/partials/w3m-swap-input/index.ts — added autoFocus property + firstUpdated()
  • packages/scaffold-ui/src/views/w3m-swap-view/index.ts — passes autoFocus to source token input

Verification

  • 15/15 w3m-swap-input tests pass
  • 14/14 w3m-swap-view tests pass
  • Type check clean
  • Existing test fixtures don't pass autoFocus, so they default to false — no behavior change for existing consumers
  • No accessibility concern — auto-focusing a primary input on a dedicated page is standard UX

Test plan

  • Open swap view — source token input should be focused automatically
  • Verify destination token input is NOT focused
  • Verify typing works immediately without clicking first

🤖 Generated with Claude Code

When the user opens the swap page, the source token input field is now
automatically focused so they can immediately start typing.

Resolves REOWN-3541

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@linear

linear Bot commented Apr 2, 2026

Copy link
Copy Markdown

@changeset-bot

changeset-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5949f25

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Apr 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
appkit-demo Ready Ready Preview, Comment Apr 2, 2026 9:27pm
appkit-gallery Ready Ready Preview, Comment Apr 2, 2026 9:27pm
appkit-headless-sample-app Ready Ready Preview, Comment Apr 2, 2026 9:27pm
appkit-laboratory Ready Ready Preview, Comment Apr 2, 2026 9:27pm
9 Skipped Deployments
Project Deployment Actions Updated (UTC)
appkit-basic-example Ignored Ignored Apr 2, 2026 9:27pm
appkit-basic-sign-client-example Ignored Ignored Apr 2, 2026 9:27pm
appkit-basic-up-example Ignored Ignored Apr 2, 2026 9:27pm
appkit-ethers5-bera Ignored Ignored Apr 2, 2026 9:27pm
appkit-nansen-demo Ignored Ignored Apr 2, 2026 9:27pm
appkit-wagmi-cdn-example Ignored Ignored Apr 2, 2026 9:27pm
ethereum-provider-wagmi-example Ignored Ignored Apr 2, 2026 9:27pm
next-wagmi-solana-bitcoin-example Ignored Ignored Apr 2, 2026 9:27pm
vue-wagmi-example Ignored Ignored Apr 2, 2026 9:27pm

Request Review

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! We ask that you please read and sign our CTA Document before we can accept your contribution. You can sign the CTA simply by posting a Pull Request Comment with the following text:


I have read the CTA Document and I hereby sign the CTA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@svenvoskamp
svenvoskamp merged commit 3b3d256 into chore/khizr-fixes Apr 13, 2026
16 of 17 checks passed
@svenvoskamp
svenvoskamp deleted the chore/khizr-fixes-REOWN-3541 branch April 13, 2026 16:28
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants