Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions app/components/AppHeader.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { onClickOutside } from '@vueuse/core'
import { LinkBase } from '#components'
import type { NavigationConfig, NavigationConfigWithGroups } from '~/types'
import { isEditableElement } from '~/utils/input'
Expand Down Expand Up @@ -143,6 +144,7 @@ const route = useRoute()
const isMobile = useIsMobile()
const isSearchExpandedManually = shallowRef(false)
const searchBoxRef = useTemplateRef('searchBoxRef')
const headerRef = useTemplateRef('headerRef')

// On search page, always show search expanded on mobile
const isOnHomePage = computed(() => route.name === 'index')
Expand All @@ -156,6 +158,21 @@ function expandMobileSearch() {
})
}

function collapseMobileSearch() {
if (!isMobile.value) return
if (isOnSearchPage.value) return
isSearchExpandedManually.value = false
if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur()
}
}

onClickOutside(headerRef, () => {
if (isMobile.value && isSearchExpanded.value && !isOnSearchPage.value) {
collapseMobileSearch()
}
})

watch(
isOnSearchPage,
visible => {
Expand All @@ -171,13 +188,6 @@ watch(

function handleSearchBlur() {
showFullSearch.value = false
// Collapse expanded search on mobile after blur (with delay for click handling)
// But don't collapse if we're on the search page
if (isMobile.value && !isOnSearchPage.value) {
setTimeout(() => {
isSearchExpandedManually.value = false
}, 150)
}
}

function handleSearchFocus() {
Expand All @@ -200,10 +210,22 @@ onKeyStroke(
},
{ dedupe: true },
)

onKeyStroke(
e =>
isKeyWithoutModifiers(e, 'Escape') &&
isMobile.value &&
isSearchExpanded.value &&
!isOnSearchPage.value,
Comment on lines +217 to +219
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this could be extracted, since we duplicate this complex condition in a few places? it would also be more expressive by self-documenting with a name

e => {
e.preventDefault()
collapseMobileSearch()
},
)
</script>

<template>
<header class="sticky top-0 z-50 border-b border-border">
<header ref="headerRef" class="sticky top-0 z-50 border-b border-border">
<div class="absolute inset-0 bg-bg/80 backdrop-blur-md" />
<nav
:aria-label="$t('nav.main_navigation')"
Expand Down Expand Up @@ -301,15 +323,25 @@ onKeyStroke(

<!-- Mobile: Search button (expands search) -->
<ButtonBase
v-if="!isSearchExpanded && !isOnHomePage"
type="button"
class="sm:hidden ms-auto"
:aria-label="$t('nav.tap_to_search')"
:aria-expanded="showMobileMenu"
:aria-expanded="isSearchExpanded"
@click="expandMobileSearch"
v-if="!isSearchExpanded && !isOnHomePage"
classicon="i-lucide:search"
/>

<!-- Mobile: Close search button (collapses search) -->
<ButtonBase
v-if="isSearchExpanded && !isOnSearchPage"
type="button"
class="sm:hidden flex-shrink-0"
:aria-label="$t('nav.close_search')"
@click="collapseMobileSearch"
classicon="i-lucide:x"
/>
Comment on lines +335 to +343
Copy link
Copy Markdown
Member

@knowler knowler Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just collapse the input if it doesn’t have a value or if it’s not focused. We shouldn’t need an additional button for this. And if I recall, we added a button to clear the input which would effectively serve the same purpose if the search did have a value.


<!-- Mobile: Menu button (always visible, click to open menu) -->
<ButtonBase
type="button"
Expand Down
2 changes: 1 addition & 1 deletion app/components/Header/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defineExpose({ focus })
name="q"
:placeholder="$t('search.placeholder')"
no-correct
class="w-full min-w-25 ps-7 pe-8"
class="w-full min-w-25 h-8 sm:h-9 ps-7 pe-8"
@focus="isSearchFocused = true"
@blur="isSearchFocused = false"
size="small"
Expand Down
3 changes: 2 additions & 1 deletion i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"mobile_menu": "Navigation menu",
"open_menu": "Open menu",
"links": "Links",
"tap_to_search": "Tap to search"
"tap_to_search": "Tap to search",
"close_search": "Close search"
},
"blog": {
"title": "Blog",
Expand Down
3 changes: 3 additions & 0 deletions i18n/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@
},
"tap_to_search": {
"type": "string"
},
"close_search": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
Loading