Skip to content

Commit 6361239

Browse files
danielroeFlo0806cullophid
committed
fix: merge in improvements from #399 and #399
Co-authored-by: Florian Heuberger <fh@flogersoft.de> Co-authored-by: cullophid <andreas.moller@gmail.com>
1 parent e74905a commit 6361239

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

app/components/AppHeader.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ function expandMobileSearch() {
3030
})
3131
}
3232
33-
watch(isOnSearchPage, () => {
33+
watch(isOnSearchPage, visible => {
34+
if (!visible) return
35+
3436
searchBoxRef.value?.focus()
3537
nextTick(() => {
3638
searchBoxRef.value?.focus()

app/components/SearchBox.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<script setup lang="ts">
22
import { debounce } from 'perfect-debounce'
33
4-
const isMobile = useIsMobile()
5-
64
withDefaults(
75
defineProps<{
86
inputClass?: string
@@ -107,7 +105,6 @@ defineExpose({ focus })
107105
<input
108106
id="header-search"
109107
ref="inputRef"
110-
:autofocus="!isMobile"
111108
v-model="searchQuery"
112109
type="search"
113110
name="q"

app/pages/index.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const searchQuery = shallowRef('')
55
const searchInputRef = useTemplateRef('searchInputRef')
66
const { focused: isSearchFocused } = useFocus(searchInputRef)
77
8-
const isMobile = useIsMobile()
9-
108
async function search() {
119
const query = searchQuery.value.trim()
1210
await navigateTo({
@@ -90,7 +88,6 @@ defineOgImageComponent('Default', {
9088
name="q"
9189
:placeholder="$t('search.placeholder')"
9290
v-bind="noCorrect"
93-
:autofocus="!isMobile"
9491
class="w-full bg-bg-subtle border border-border rounded-lg ps-8 pe-24 py-4 font-mono text-base text-fg placeholder:text-fg-subtle transition-border-color duration-300 focus:border-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
9592
@input="handleInput"
9693
/>

test/e2e/interactions.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ test.describe('Search Pages', () => {
3535
await expect(page.locator('input[type="search"]')).toBeFocused()
3636
})
3737

38+
test('/ (homepage) → search, keeps focus on search input', async ({ page, goto }) => {
39+
await goto('/', { waitUntil: 'domcontentloaded' })
40+
41+
const homeSearchInput = page.locator('#home-search')
42+
await homeSearchInput.click()
43+
await page.keyboard.type('vue')
44+
45+
// Wait for navigation to /search (debounce is 250ms)
46+
await expect(page).toHaveURL(/\/search/, { timeout: 10000 })
47+
await expect(page.locator('text=/found \\d+/i')).toBeVisible({ timeout: 15000 })
48+
49+
// Home search input should be gone (we're on /search now)
50+
await expect(homeSearchInput).not.toBeVisible()
51+
52+
// Header search input should now exist and be focused
53+
const headerSearchInput = page.locator('#header-search')
54+
await expect(headerSearchInput).toBeVisible()
55+
await expect(headerSearchInput).toBeFocused()
56+
})
57+
3858
test('/settings → search, keeps focus on search input', async ({ page, goto }) => {
3959
await goto('/settings', { waitUntil: 'domcontentloaded' })
4060

0 commit comments

Comments
 (0)