Skip to content

Conversation

@italomatos
Copy link
Contributor

@italomatos italomatos commented Dec 16, 2025

Problem:
When pressing Enter in the search input field, focus was lost after the form was submitted and the Turbo Frame updated with search results. This forced users to click back into the field to continue interacting with the search.

Video: git push --set-upstream origin fix/maintain-search-input-focus-on-submit

https://jam.dev/c/982fcbfc-87a6-4bab-9c1a-a0628d54ed98

Solution:
Added a turbo:frame-load event listener in the bar controller's showModalAndSubmit method that automatically restores focus to the search input after the Turbo Frame finishes loading the results. The listener uses {once: true} to auto-cleanup after execution.

Problem:
When pressing Enter in the search input field, focus was lost after
the form was submitted and the Turbo Frame updated with search results.
This forced users to click back into the field to continue interacting
with the search.

Solution:
Added a turbo:frame-load event listener in the bar controller's
showModalAndSubmit method that automatically restores focus to the
search input after the Turbo Frame finishes loading the results.
The listener uses {once: true} to auto-cleanup after execution.
Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment but 👍 to this one @italomatos thanks

this.showModal()
this.formTarget.requestSubmit()

// Restore focus to search input after turbo frame loads
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could consider extracting a method #restoreFocusAfterTurboFrameLoads() to remove the comment and keep the showModalAndsubmit sentences working at the same level of abstraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, @jorgemanrubia ! That makes a lot of sense. Thanks a lot for the review.

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.

2 participants