Skip to content

Commit a8acc32

Browse files
committed
fix(arena): generate auto focus
1 parent 614f12e commit a8acc32

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/views/Arena/AutoFocus.vue

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@ import { Checkbox } from "@/components"
44
import { useArenaStore } from "./store"
55
import { storeToRefs } from "pinia"
66
import { watchEffect } from "vue"
7+
import { useDialogObserver } from "@/hooks"
78
89
const arenaStore = useArenaStore()
910
const { shouldAutoFocusGenerate } = storeToRefs(arenaStore)
1011
1112
const buttons = Array.from(document.querySelectorAll<HTMLButtonElement>(".col-span-2 button"))
1213
const generateButton = buttons.find((b) => b.innerText.toLowerCase().includes("generate"))
1314
15+
useDialogObserver({
16+
toggle: shouldAutoFocusGenerate,
17+
onOpen: ({ el }) => {
18+
const button = el.querySelector<HTMLButtonElement>("button.w-full.justify-center.rounded-md")
19+
if (!button) return
20+
if (!["generate", "battle"].some((key) => button.innerText.toLowerCase().includes(key))) return
21+
22+
const TRANSITION_TIMEOUT = 200
23+
setTimeout(() => {
24+
button.focus()
25+
}, TRANSITION_TIMEOUT)
26+
},
27+
})
28+
1429
watchEffect(() => {
1530
if (!generateButton) return
1631
if (!shouldAutoFocusGenerate.value) return
@@ -25,5 +40,3 @@ watchEffect(() => {
2540
<template #subtitle> Just hit space/enter! </template>
2641
</Checkbox>
2742
</template>
28-
29-
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)