File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import { debounce } from ' perfect-debounce'
33
4- const isMobile = useIsMobile ()
5-
64withDefaults (
75 defineProps <{
86 inputClass? : string
@@ -60,6 +58,15 @@ watch(
6058 },
6159)
6260
61+ const autofocus = import .meta .client && ! isTouchDevice ()
62+ const headerSearchRef = useTemplateRef (' headerSearchRef' )
63+ onMounted (() => {
64+ // Autofocus the search input on page load for non-touch devicese
65+ if (! isTouchDevice ()) {
66+ headerSearchRef .value ?.focus ()
67+ }
68+ })
69+
6370function handleSearchBlur() {
6471 isSearchFocused .value = false
6572 emit (' blur' )
@@ -86,9 +93,10 @@ function handleSearchFocus() {
8693
8794 <input
8895 id =" header-search"
89- :autofocus = " !isMobile "
96+ ref = " headerSearchRef "
9097 v-model =" searchQuery"
9198 type =" search"
99+ :autofocus =" autofocus"
92100 name =" q"
93101 :placeholder =" $t('search.placeholder')"
94102 v-bind =" noCorrect"
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -6,7 +6,13 @@ const searchQuery = ref('')
66const searchInputRef = useTemplateRef (' searchInputRef' )
77const { focused : isSearchFocused } = useFocus (searchInputRef )
88
9- const isMobile = useIsMobile ()
9+ const autofocus = import .meta .client && ! isTouchDevice ()
10+ onMounted (() => {
11+ // Autofocus the search input on page load for non-touch devices
12+ if (! isTouchDevice ()) {
13+ searchInputRef .value ?.focus ()
14+ }
15+ })
1016
1117const debouncedNavigate = debounce (() => {
1218 router .push ({
@@ -78,7 +84,7 @@ defineOgImageComponent('Default')
7884 name =" q"
7985 :placeholder =" $t('search.placeholder')"
8086 v-bind =" noCorrect"
81- :autofocus =" !isMobile "
87+ :autofocus =" autofocus "
8288 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"
8389 @input =" handleSearch"
8490 />
Original file line number Diff line number Diff line change 1+ /** @public */
2+ export function isTouchDevice ( ) {
3+ if ( import . meta. server ) {
4+ return false
5+ }
6+ return (
7+ 'ontouchstart' in window ||
8+ navigator . maxTouchPoints > 0 ||
9+ // @ts -ignore
10+ navigator . msMaxTouchPoints > 0
11+ )
12+ }
You can’t perform that action at this time.
0 commit comments