Repository navigation
Search field: take focus only when the customer opens it - #2742
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Written by 🤖:
SearchFieldgave the input a new focus ref on each render. React calls a new ref again, so the input took the focus on each render:visible(always shown in the header) takes the focus on each page load.SearchFieldrenders again on each route change (useSearchPageAndParamusesuseRouter). On the search page the focus jumps back to the field after a filter changes the URL.SearchFielduses 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 callsrouter.replacewith a new query parameter, as a filter does./with the collapsed header field: focus after loadbodybody/search/shirt: focus after load/search/shirt: focus after a route change/withvisibleon the header field: focus after loadbody/withvisible: focus after a route change/, click the search button in the header: the field opens with focus./search/shirt, open a filter and select an option: the focus stays in the filter.