Skip to content

Commit db5aa6f

Browse files
committed
fix(a11y): add instant search advisory to homepage search field
1 parent 2786639 commit db5aa6f

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

app/app.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ if (import.meta.server) {
4848
}
4949
5050
const keyboardShortcuts = useKeyboardShortcuts()
51+
const { settings } = useSettings()
5152
5253
onKeyDown(
5354
'/',
5455
e => {
56+
if (e.ctrlKey) {
57+
e.preventDefault()
58+
settings.value.instantSearch = !settings.value.instantSearch
59+
return
60+
}
61+
5562
if (!keyboardShortcuts.value || isEditableElement(e.target)) return
5663
e.preventDefault()
5764

app/pages/index.vue

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup lang="ts">
22
import { SHOWCASED_FRAMEWORKS } from '~/utils/frameworks'
33
4+
const { settings } = useSettings()
5+
46
const { model: searchQuery, startSearch } = useGlobalSearch()
57
const isSearchFocused = shallowRef(false)
68
@@ -52,15 +54,20 @@ defineOgImageComponent('Default', {
5254
{{ $t('tagline') }}
5355
</p>
5456
<search
55-
class="w-full max-w-xl motion-safe:animate-slide-up motion-safe:animate-fill-both"
57+
class="w-full max-w-2xl motion-safe:animate-slide-up motion-safe:animate-fill-both"
5658
style="animation-delay: 0.2s"
5759
>
58-
<form method="GET" action="/search" class="relative" @submit.prevent.trim="search">
60+
<form
61+
method="GET"
62+
action="/search"
63+
class="relative grid justify-items-center gap-4"
64+
@submit.prevent.trim="search"
65+
>
5966
<label for="home-search" class="sr-only">
6067
{{ $t('search.label') }}
6168
</label>
6269

63-
<div class="relative group" :class="{ 'is-focused': isSearchFocused }">
70+
<div class="relative group w-full max-w-xl" :class="{ 'is-focused': isSearchFocused }">
6471
<div
6572
class="absolute z-1 -inset-px pointer-events-none rounded-lg bg-gradient-to-r from-fg/0 to-accent/5 opacity-0 transition-opacity duration-500 blur-sm group-[.is-focused]:opacity-100"
6673
/>
@@ -82,6 +89,7 @@ defineOgImageComponent('Default', {
8289
no-correct
8390
size="large"
8491
class="w-full ps-8 pe-24"
92+
aria-describedby="instant-search-advisory"
8593
@focus="isSearchFocused = true"
8694
@blur="isSearchFocused = false"
8795
/>
@@ -98,6 +106,35 @@ defineOgImageComponent('Default', {
98106
</ButtonBase>
99107
</div>
100108
</div>
109+
110+
<p
111+
v-if="settings.instantSearch"
112+
id="instant-search-advisory"
113+
class="text-fg-muted text-sm text-pretty"
114+
>
115+
<span
116+
class="i-lucide:zap align-middle text-fg relative top-[-0.1em] me-1"
117+
style="font-size: 0.8em"
118+
aria-hidden="true"
119+
></span>
120+
<i18n-t keypath="search.instant_search_advisory">
121+
<template #label>
122+
<strong>{{ $t('search.instant_search') }}</strong>
123+
</template>
124+
<template #settings>
125+
<LinkBase to="/settings">{{ $t('settings.title') }}</LinkBase>
126+
</template>
127+
<template #shortcut>
128+
<kbd class="text-xs"
129+
><kbd class="text-fg bg-bg-muted border border-border px-1 py-[2px] rounded-sm"
130+
>Ctrl</kbd
131+
>+<kbd class="text-fg bg-bg-muted border border-border px-1 py-[2px] rounded-sm"
132+
>/</kbd
133+
></kbd
134+
>
135+
</template>
136+
</i18n-t>
137+
</p>
101138
</form>
102139
</search>
103140

i18n/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
"org": "org",
6565
"view_user_packages": "View packages by this user",
6666
"view_org_packages": "View packages by this organization"
67-
}
67+
},
68+
"instant_search": "Instant search",
69+
"instant_search_advisory": "{label}: navigate to results as you type. Turn off in {settings} or press {shortcut}."
6870
},
6971
"nav": {
7072
"main_navigation": "Main",

i18n/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@
198198
}
199199
},
200200
"additionalProperties": false
201+
},
202+
"instant_search": {
203+
"type": "string"
204+
},
205+
"instant_search_advisory": {
206+
"type": "string"
201207
}
202208
},
203209
"additionalProperties": false

0 commit comments

Comments
 (0)