File tree 2 files changed +25
-6
lines changed
2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 1
1
<!-- This content is mostly copied over from https://github.com /vuejs/docs/blob/main/src/api/ApiIndex.vue -->
2
2
3
3
<script setup lang="ts">
4
- import { computed, ref } from 'vue';
4
+ import { computed, onMounted, onUnmounted, ref } from 'vue';
5
5
import { slugify } from '../.vitepress/shared/utils/slugify';
6
6
import apiSearchIndex from './api-search-index.json';
7
7
import { APIGroup } from './api-types';
@@ -43,6 +43,29 @@ const filtered = computed(() => {
43
43
})
44
44
.filter((i) => i) as APIGroup[];
45
45
});
46
+
47
+ const apiFilter = ref<HTMLInputElement>();
48
+
49
+ function apiSearchFocusHandler(event: KeyboardEvent): void {
50
+ if (event.key === 'Escape') {
51
+ if (apiFilter.value !== document.activeElement) {
52
+ query.value = '';
53
+ } else {
54
+ apiFilter.value!.blur();
55
+ }
56
+ } else if (
57
+ /^[a-z]$/.test(event.key) &&
58
+ !event.altKey &&
59
+ !event.ctrlKey &&
60
+ !event.shiftKey &&
61
+ !event.metaKey
62
+ ) {
63
+ apiFilter.value!.focus();
64
+ }
65
+ }
66
+
67
+ onMounted(() => window.addEventListener('keydown', apiSearchFocusHandler));
68
+ onUnmounted(() => window.removeEventListener('keydown', apiSearchFocusHandler));
46
69
</script>
47
70
48
71
<template>
@@ -54,6 +77,7 @@ const filtered = computed(() => {
54
77
<input
55
78
type="search"
56
79
placeholder="Enter keyword"
80
+ ref="apiFilter"
57
81
id="api-filter"
58
82
v-model="query"
59
83
/>
Original file line number Diff line number Diff line change 8
8
"esModuleInterop" : true ,
9
9
"allowJs" : true ,
10
10
"alwaysStrict" : true ,
11
- // "strictNullChecks": true,
12
- // "strictBindCallApply": true,
13
11
"strictFunctionTypes" : true ,
14
- // "strictPropertyInitialization": true,
15
- // "noImplicitAny": true,
16
- // "noImplicitThis": true,
17
12
"useUnknownInCatchVariables" : true ,
18
13
"stripInternal" : true ,
19
14
"baseUrl" : " ."
You can’t perform that action at this time.
0 commit comments