|
1 | 1 | <template> |
2 | | - <Transition name="fade"> |
3 | | - <div |
4 | | - class="fixed inset-0 z-[1000] flex items-start justify-center bg-black/50 backdrop-blur-sm" |
5 | | - v-show="show" |
6 | | - > |
| 2 | + <Teleport to="body"> |
| 3 | + <Transition name="fade"> |
7 | 4 | <div |
8 | | - class="cmdbar-container flex items-center justify-center border border-border shadow-lg rounded-xl bg-bg p2 flex-col gap-2 mt-5rem" |
| 5 | + class="fixed inset-0 z-[1000] flex items-start justify-center bg-black/50 backdrop-blur-sm" |
| 6 | + v-show="show" |
9 | 7 | > |
10 | | - <label for="command-input" class="sr-only">command-input</label> |
11 | | - |
12 | | - <search class="relative w-xl h-12 flex items-center"> |
13 | | - <span class="absolute inset-is-4 text-fg-subtle font-mono pointer-events-none"> > </span> |
14 | | - <input |
15 | | - type="text" |
16 | | - v-model="inputVal" |
17 | | - id="command-input" |
18 | | - ref="inputRef" |
19 | | - class="w-full h-full px-4 pl-8 text-fg outline-none bg-bg-subtle border border-border rounded-md" |
20 | | - :placeholder="placeholderText" |
21 | | - @keydown="handleKeydown" |
22 | | - /> |
23 | | - </search> |
24 | | - |
25 | | - <div class="w-xl max-h-lg overflow-auto" v-if="view.type != 'INPUT'"> |
26 | | - <div |
27 | | - v-for="item in filteredCmdList" |
28 | | - :key="item.id" |
29 | | - class="flex-col items-center justify-between px-4 py-2 not-first:mt-2 hover:bg-bg-elevated select-none cursor-pointer rounded-md transition" |
30 | | - :class="{ |
31 | | - 'bg-bg-subtle': item.id === selected, |
32 | | - 'trigger-anim': item.id === triggeringId, |
33 | | - }" |
34 | | - @click="onTrigger(item.id)" |
35 | | - > |
36 | | - <div class="text-fg">{{ item.name }}</div> |
37 | | - <div class="text-fg-subtle text-sm">{{ item.description }}</div> |
| 8 | + <div |
| 9 | + class="cmdbar-container flex items-center justify-center border border-border shadow-lg rounded-xl bg-bg p2 flex-col gap-2 mt-5rem" |
| 10 | + role="dialog" |
| 11 | + aria-modal="true" |
| 12 | + aria-labelledby="command-input-label" |
| 13 | + > |
| 14 | + <label for="command-input" id="command-input-label" class="sr-only">{{ |
| 15 | + t('command.label') |
| 16 | + }}</label> |
| 17 | + |
| 18 | + <search class="relative w-xl h-12 flex items-center"> |
| 19 | + <span class="absolute inset-is-4 text-fg-subtle font-mono pointer-events-none"> |
| 20 | + > |
| 21 | + </span> |
| 22 | + <input |
| 23 | + type="text" |
| 24 | + v-model="inputVal" |
| 25 | + id="command-input" |
| 26 | + ref="inputRef" |
| 27 | + class="w-full h-full px-4 pl-8 text-fg outline-none bg-bg-subtle border border-border rounded-md" |
| 28 | + :placeholder="placeholderText" |
| 29 | + @keydown="handleKeydown" |
| 30 | + /> |
| 31 | + </search> |
| 32 | + |
| 33 | + <div class="w-xl max-h-lg overflow-auto" v-if="view.type != 'INPUT'"> |
| 34 | + <div |
| 35 | + v-for="item in filteredCmdList" |
| 36 | + :key="item.id" |
| 37 | + class="px-4 py-2 not-first:mt-2 hover:bg-bg-elevated select-none cursor-pointer rounded-md transition" |
| 38 | + :class="{ |
| 39 | + 'bg-bg-subtle': item.id === selected, |
| 40 | + 'trigger-anim': item.id === triggeringId, |
| 41 | + }" |
| 42 | + @click="onTrigger(item.id)" |
| 43 | + > |
| 44 | + <div class="text-fg">{{ item.name }}</div> |
| 45 | + <div class="text-fg-subtle text-sm">{{ item.description }}</div> |
| 46 | + </div> |
38 | 47 | </div> |
39 | 48 | </div> |
40 | 49 | </div> |
41 | | - </div> |
42 | | - </Transition> |
| 50 | + </Transition> |
| 51 | + </Teleport> |
43 | 52 | </template> |
44 | 53 |
|
45 | 54 | <script setup lang="ts"> |
@@ -164,6 +173,11 @@ const handleKeydown = useThrottleFn((e: KeyboardEvent) => { |
164 | 173 | return |
165 | 174 | } |
166 | 175 |
|
| 176 | + if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !filteredCmdList.value.length) { |
| 177 | + e.preventDefault() |
| 178 | + return |
| 179 | + } |
| 180 | +
|
167 | 181 | const currentIndex = filteredCmdList.value.findIndex((item: any) => item.id === selected.value) |
168 | 182 |
|
169 | 183 | if (e.key === 'ArrowDown') { |
|
0 commit comments