Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/javascript/controllers/bar_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default class extends Controller {
showModalAndSubmit(event) {
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.

this.turboFrameTarget.addEventListener("turbo:frame-load", () => {
this.searchInputTarget.focus()
}, { once: true })
}

showModal() {
Expand Down