Skip to content

Commit 68ddbfc

Browse files
authored
feat(ui): highlight slash keyboard shortcut on header/home search bars (#1960)
1 parent ef0f696 commit 68ddbfc

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

app/components/Header/SearchBox.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ defineExpose({ focus })
4444

4545
<div class="relative group" :class="{ 'is-focused': isSearchFocused }">
4646
<div class="search-box relative flex items-center">
47-
<span
48-
class="absolute inset-is-3 text-fg-subtle font-mono text-sm pointer-events-none transition-colors duration-200 motion-reduce:transition-none [.group:hover:not(:focus-within)_&]:text-fg/80 group-focus-within:text-accent z-1"
47+
<kbd
48+
class="absolute inset-is-3 text-fg-subtle font-mono text-sm pointer-events-none transition-colors duration-200 motion-reduce:transition-none [.group:hover:not(:focus-within)_&]:text-fg/80 group-focus-within:text-accent z-1 rounded"
49+
aria-hidden="true"
4950
>
5051
/
51-
</span>
52+
</kbd>
5253

5354
<InputBase
5455
id="header-search"
@@ -62,6 +63,7 @@ defineExpose({ focus })
6263
@focus="isSearchFocused = true"
6364
@blur="isSearchFocused = false"
6465
size="small"
66+
ariaKeyshortcuts="/"
6567
/>
6668
<button
6769
v-if="hasSearchQuery"

app/components/Input/Base.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const props = withDefaults(
1414
* @default true
1515
*/
1616
noCorrect?: boolean
17+
/** Keyboard shortcut hint */
18+
ariaKeyshortcuts?: string
1719
}>(),
1820
{
1921
size: 'medium',
@@ -28,6 +30,8 @@ const emit = defineEmits<{
2830
2931
const el = useTemplateRef('el')
3032
33+
const keyboardShortcutsEnabled = useKeyboardShortcuts()
34+
3135
defineExpose({
3236
focus: () => el.value?.focus(),
3337
blur: () => el.value?.blur(),
@@ -51,5 +55,6 @@ defineExpose({
5155
/** Catching Vue render-bug of invalid `disabled=false` attribute in the final HTML */
5256
disabled ? true : undefined
5357
"
58+
:aria-keyshortcuts="keyboardShortcutsEnabled ? ariaKeyshortcuts : undefined"
5459
/>
5560
</template>

app/pages/index.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ defineOgImageComponent('Default', {
7171
/>
7272

7373
<div class="search-box relative flex items-center">
74-
<span
75-
class="absolute inset-is-4 text-fg-subtle font-mono text-lg pointer-events-none transition-colors duration-200 motion-reduce:transition-none [.group:hover:not(:focus-within)_&]:text-fg/80 group-focus-within:text-accent z-1"
74+
<kbd
75+
class="absolute inset-is-4 text-fg-subtle font-mono text-lg pointer-events-none transition-colors duration-200 motion-reduce:transition-none [.group:hover:not(:focus-within)_&]:text-fg/80 group-focus-within:text-accent z-1 rounded"
76+
aria-hidden="true"
7677
>
7778
/
78-
</span>
79+
</kbd>
7980

8081
<InputBase
8182
id="home-search"
@@ -90,6 +91,7 @@ defineOgImageComponent('Default', {
9091
aria-describedby="instant-search-advisory"
9192
@focus="isSearchFocused = true"
9293
@blur="isSearchFocused = false"
94+
ariaKeyshortcuts="/"
9395
/>
9496

9597
<ButtonBase

0 commit comments

Comments
 (0)