Skip to content

Search field: take focus only when the customer opens it - #2742

Merged
bramvanderholst merged 1 commit into
canaryfrom
fix/search-field-focus
Dec 4, 2026
Merged

bramvanderholst merged 1 commit into
canaryfrom
fix/search-field-focus

Conversation

@bramvanderholst

Copy link
Copy Markdown
Contributor

Written by 🤖:

SearchField gave the input a new focus ref on each render. React calls a new ref again, so the input took the focus on each render:

  • A field with visible (always shown in the header) takes the focus on each page load.
  • SearchField renders again on each route change (useSearchPageAndParam uses useRouter). On the search page the focus jumps back to the field after a filter changes the URL.

SearchField uses one stable ref and gives it to the input only while the field is expanded. The input takes the focus once: when the customer opens the field, or when the search page loads. Three client projects patch this behaviour.

Test plan

Checked in Chrome with Playwright against examples/magento-graphcms (next dev). "Route change" focuses another button and calls router.replace with a new query parameter, as a filter does.

Situation canary this PR
/ with the collapsed header field: focus after load body body
Click the search button in the header input input
/search/shirt: focus after load input input
/search/shirt: focus after a route change input (jumps back) the other button
/ with visible on the header field: focus after load input body
/ with visible: focus after a route change input (jumps back) the other button
  • Open /, click the search button in the header: the field opens with focus.
  • Open /search/shirt, open a filter and select an option: the focus stays in the filter.

@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
graphcommerce-246 Ready Ready Preview Dec 4, 2026 2:27pm UTC
graphcommerce-247 Ready Ready Preview Dec 4, 2026 2:27pm UTC
graphcommerce-hygraph-dynamic-rows-ui Ready Ready Preview Dec 4, 2026 2:27pm UTC
graphcommerce-open-source Ready Ready Preview Dec 4, 2026 2:27pm UTC
graphcommerce-storyblok Ready Ready Preview Dec 4, 2026 2:27pm UTC

Request Review

This branch was successfully deployed

5 active deployments
Preview – graphcommerce-246 — c3f870c8 Deployed Dec 4, 2026 by vercel[bot]
Preview – graphcommerce-open-source — c3f870c8 Deployed Dec 4, 2026 by vercel[bot]
Preview – graphcommerce-storyblok — c3f870c8 Deployed Dec 4, 2026 by vercel[bot]
Preview – graphcommerce-247 — c3f870c8 Deployed Dec 4, 2026 by vercel[bot]
Preview – graphcommerce-hygraph-dynamic-rows-ui — c3f870c8 Deployed Dec 4, 2026 by vercel[bot]
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