fix: restore focus after search submission (#914) #1107
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.
Summary
Fixes #914 - Restores focus management after search submission to improve keyboard navigation and screen reader accessibility.
Problem: When users clicked the "Submit search" button, focus was lost as the button disappeared from the DOM and was replaced with the "Clear search input" button. This created an accessibility barrier for keyboard and screen reader users who lost their place in the interface.
Solution: Implemented automatic focus transfer to the clear button after search submission using
useEffectto track state transitions. Also removed thekeyprop that was causing component remounts so that we can preserve the state tracking required for focus management.Changes:
clearButtonRefand focus management logic to automatically focus clear button after search submission.isInputEditedstate to detect transitions (prevents unwanted focus on initial render).key={searchTerm}prop from SearchResults - this was causing the component to unmount/remount on every search, which would clear theprevIsInputEditedstate and break focus management. Replace remount-based state reset withuseEffectfor better performance and to preserve component state.Demo
After
Screen.Recording.2026-01-26.at.18.01.39.mov