diff --git a/app/javascript/controllers/bar_controller.js b/app/javascript/controllers/bar_controller.js index 522e3eee3..e83bce9a9 100644 --- a/app/javascript/controllers/bar_controller.js +++ b/app/javascript/controllers/bar_controller.js @@ -34,11 +34,7 @@ export default class extends Controller { showModalAndSubmit(event) { this.showModal() this.formTarget.requestSubmit() - - // Restore focus to search input after turbo frame loads - this.turboFrameTarget.addEventListener("turbo:frame-load", () => { - this.searchInputTarget.focus() - }, { once: true }) + this.#restoreFocusAfterTurboFrameLoads() } showModal() { @@ -56,6 +52,12 @@ export default class extends Controller { } } + #restoreFocusAfterTurboFrameLoads() { + this.turboFrameTarget.addEventListener("turbo:frame-load", () => { + this.searchInputTarget.focus() + }, { once: true }) + } + #loadTurboFrame() { this.turboFrameTarget.src = this.searchUrlValue }