From d66e2f0b8ac9991bc45c96ecbcaf35614423cb7e Mon Sep 17 00:00:00 2001 From: Italo Matos Date: Fri, 19 Dec 2025 12:33:00 -0300 Subject: [PATCH] remove comment and move logic to method --- app/javascript/controllers/bar_controller.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 }