Skip to content

Commit ac38c26

Browse files
committed
feat(travel): add button step autofocus
1 parent 52f0794 commit ac38c26

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/views/Travel/AutoFocus.vue

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script setup lang="ts">
2+
import { onMounted, watch } from "vue"
3+
import { useTravelStore } from "@/store"
4+
import { storeToRefs } from "pinia"
5+
6+
const travelStore = useTravelStore()
7+
const { cooldownTimeLeft } = storeToRefs(travelStore)
8+
9+
const travelButton = document.querySelector<HTMLButtonElement>(".px-4.py-4 button")
10+
11+
watch(
12+
cooldownTimeLeft,
13+
(val) => {
14+
if (!val) return
15+
if (!travelButton) return
16+
17+
setTimeout(() => {
18+
travelButton.focus()
19+
}, val + 10)
20+
},
21+
{
22+
immediate: true,
23+
}
24+
)
25+
26+
onMounted(() => {
27+
if (!travelButton) return
28+
travelButton.focus()
29+
})
30+
</script>
31+
32+
<template>
33+
<slot></slot>
34+
</template>

src/views/Travel/Travel.vue

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import TravelBridge from "./TravelBridge.vue"
33
import TravelBar from "./TravelBar.vue"
44
import TravelButton from "./TravelButton.vue"
5+
import AutoFocus from "./AutoFocus.vue"
56
</script>
67

78
<template>
89
<TravelBridge />
910
<TravelBar />
1011
<TravelButton />
12+
<AutoFocus />
1113
</template>

0 commit comments

Comments
 (0)