|
1 | 1 | <script setup lang="ts"> |
2 | | -import { ref, computed } from 'vue' |
3 | | -import { onKeyDown } from '@vueuse/core' |
4 | | -
|
5 | 2 | const route = useRoute() |
6 | 3 | const isHome = computed(() => route.name === 'index') |
7 | 4 |
|
8 | | -const triggerRef = useTemplateRef('triggerRef') |
9 | 5 | const modalRef = useTemplateRef('modalRef') |
10 | | -const modalOpen = ref(false) |
11 | | -
|
12 | | -const togglePopover = (e?: Event) => { |
13 | | - e?.stopPropagation() |
14 | | - if (!modalOpen.value) { |
15 | | - modalRef.value?.showModal?.() |
16 | | - modalOpen.value = true |
17 | | - } else { |
18 | | - modalRef.value?.close?.() |
19 | | - modalOpen.value = false |
20 | | - } |
21 | | -} |
22 | | -
|
23 | | -onKeyDown( |
24 | | - 'Escape', |
25 | | - (e: KeyboardEvent) => { |
26 | | - if (!modalOpen.value) return |
27 | | - e.preventDefault() |
28 | | - e.stopImmediatePropagation() |
29 | | - modalRef.value?.close?.() |
30 | | - modalOpen.value = false |
31 | | - }, |
32 | | - { dedupe: true }, |
33 | | -) |
34 | | -
|
35 | | -function onModalClosed() { |
36 | | - modalOpen.value = false |
37 | | - triggerRef.value?.focus?.() |
38 | | -} |
| 6 | +const showModal = () => modalRef.value?.showModal?.() |
39 | 7 | </script> |
40 | 8 |
|
41 | 9 | <template> |
@@ -70,19 +38,16 @@ function onModalClosed() { |
70 | 38 | </LinkBase> |
71 | 39 |
|
72 | 40 | <button |
73 | | - ref="triggerRef" |
74 | 41 | type="button" |
75 | 42 | class="group inline-flex gap-x-1 items-center justify-center underline-offset-[0.2rem] underline decoration-1 decoration-fg/30 font-mono text-fg hover:(decoration-accent text-accent) focus-visible:(decoration-accent text-accent) transition-colors duration-200" |
76 | | - @click.prevent="togglePopover" |
77 | | - :aria-expanded="modalOpen ? 'true' : 'false'" |
| 43 | + @click.prevent="showModal" |
78 | 44 | aria-haspopup="dialog" |
79 | 45 | > |
80 | 46 | {{ $t('footer.keyboard_shortcuts') }} |
81 | 47 | </button> |
82 | 48 |
|
83 | 49 | <Modal |
84 | 50 | ref="modalRef" |
85 | | - @close="onModalClosed" |
86 | 51 | :modalTitle="$t('footer.keyboard_shortcuts')" |
87 | 52 | class="w-auto max-w-lg" |
88 | 53 | > |
|
0 commit comments