File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,12 +15,22 @@ const emit = defineEmits(['blur', 'focus'])
1515const router = useRouter ()
1616const route = useRoute ()
1717
18+ const searchInputRef = useTemplateRef (' searchInputRef' )
1819const isSearchFocused = ref (false )
1920
2021const showSearchBar = computed (() => {
2122 return route .name !== ' index'
2223})
2324
25+ // Focus input when search bar becomes visible (e.g., when navigating from homepage)
26+ watch (showSearchBar , visible => {
27+ if (visible ) {
28+ nextTick (() => {
29+ searchInputRef .value ?.focus ()
30+ })
31+ }
32+ })
33+
2434// Local input value (updates immediately as user types)
2535const searchQuery = ref ((route .query .q as string ) ?? ' ' )
2636
@@ -84,7 +94,7 @@ function handleSearchFocus() {
8494
8595 <input
8696 id =" header-search"
87- autofocus
97+ ref = " searchInputRef "
8898 v-model =" searchQuery"
8999 type =" search"
90100 name =" q"
You can’t perform that action at this time.
0 commit comments