From 0811ba83d8d07adf34235664fefe6410aa0a5ef9 Mon Sep 17 00:00:00 2001 From: dev-guy Date: Mon, 30 Jun 2025 22:22:28 -0700 Subject: [PATCH 1/3] fix: preserve search input focus after debounced query - Add focus preservation before LiveView updates - Restore focus after component re-initialization - Set cursor to end of input for better UX - Particularly important on mobile to prevent keyboard flickering - Fixes focus loss during search debouncing --- assets/vendor/search_combobox.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/vendor/search_combobox.js b/assets/vendor/search_combobox.js index a4bffc2..0b80340 100644 --- a/assets/vendor/search_combobox.js +++ b/assets/vendor/search_combobox.js @@ -24,6 +24,9 @@ const SearchCombobox = { const wasSearching = this.searchTerm && this.searchTerm.length > 0; const preservedSearchTerm = this.searchTerm || ''; + // IMPORTANT: Check if search input was focused before update + const searchInputWasFocused = this.searchInput && document.activeElement === this.searchInput; + const wasDropdownShouldBeOpen = this.dropdownShouldBeOpen; this.init(); @@ -45,6 +48,15 @@ const SearchCombobox = { // Delay initialization to ensure LiveView updates are complete setTimeout(() => { this.initializeSelection(); + + // IMPORTANT: Restore focus to search input if it was focused before update + // This prevents focus loss during debounced search, especially important on mobile + if (searchInputWasFocused && this.searchInput && (wasOpen || wasSearching)) { + this.searchInput.focus(); + // Set cursor position to end of input for better UX + const length = this.searchInput.value.length; + this.searchInput.setSelectionRange(length, length); + } }, 0); if (wasOpen || wasSearching) { From a52643f3916ed0bf1a86dd1190b2f2a974f6f78f Mon Sep 17 00:00:00 2001 From: dev-guy Date: Mon, 30 Jun 2025 22:25:35 -0700 Subject: [PATCH 2/3] Misc --- lib/geo_web/components/layouts/app.html.heex | 62 +++++++++++-------- lib/geo_web/components/layouts/root.html.heex | 4 +- lib/geo_web/components/theme_toggle.ex | 2 +- lib/geo_web/live/home_live.ex | 20 +++--- 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/lib/geo_web/components/layouts/app.html.heex b/lib/geo_web/components/layouts/app.html.heex index c7fd577..91ab119 100644 --- a/lib/geo_web/components/layouts/app.html.heex +++ b/lib/geo_web/components/layouts/app.html.heex @@ -1,57 +1,67 @@
-
-
- - - -

- v{Application.spec(:phoenix, :vsn)} | v{Application.spec(:geo, :vsn)} -

- - GitHub - + +
+ +
+
+ + Phoenix Framework + +

+ v{Application.spec(:phoenix, :vsn)} | v{Application.spec(:geo, :vsn)} +

+
+
+ + GitHub + + +
+
+ + + -
diff --git a/lib/geo_web/components/layouts/root.html.heex b/lib/geo_web/components/layouts/root.html.heex index ab73f41..c836411 100644 --- a/lib/geo_web/components/layouts/root.html.heex +++ b/lib/geo_web/components/layouts/root.html.heex @@ -6,8 +6,8 @@ - <.live_title default="Geo" suffix=" ยท Phoenix Framework"> - {assigns[:page_title]} + <.live_title default="Geo"> + {assigns[:page_title] || "Geo"}