feat: autofocus name input when PlayerDialog is opened

This commit is contained in:
Settel 2022-09-07 15:07:12 +02:00
parent 446bc99309
commit e961797c7b
2 changed files with 9 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<ModalDialog v-if="show" :title="title" @close="emit('close')"> <ModalDialog :title="title" @close="emit('close')">
<label class="player-dialog__label">Name</label> <label class="player-dialog__label">Name</label>
<input class="player-dialog__input" v-model="player.name" size="40" /> <input id="player-dialog-name" class="player-dialog__input" v-model="player.name" size="40"/>
<label class="player-dialog__label">Score</label> <label class="player-dialog__label">Score</label>
<input class="player-dialog__input" v-model="player.score" size="40" maxlength="4" /> <input class="player-dialog__input" v-model="player.score" size="40" maxlength="4" />
<label class="player-dialog__label">Authcode</label> <label class="player-dialog__label">Authcode</label>
@ -22,20 +22,23 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue' import { onMounted, ref, watch } from 'vue'
import { PlayerEdit } from '@/composables/engine.d' import { PlayerEdit } from '@/composables/engine.d'
import type { Button } from '@/components/admin/PlayerModal' import type { Button } from '@/components/admin/PlayerModal'
const props = defineProps<{ const props = defineProps<{
title: string title: string
show: boolean
buttons: Array<Button> buttons: Array<Button>
player: PlayerEdit player: PlayerEdit
}>() }>()
const emit = defineEmits(['close', 'submit']) const emit = defineEmits(['close', 'submit'])
const showId = ref(false) const showId = ref(false)
watch([props], () => { showId.value = false }) // reset visibility each time the dialog is shown onMounted(() => {
window.setTimeout(() => {
document.getElementById('player-dialog-name')?.focus()
}, 0)
})
const generate = () => { const generate = () => {
props.player.authcode = '' props.player.authcode = ''

View File

@ -21,7 +21,7 @@
</tr> </tr>
</table> </table>
</AdminTile> </AdminTile>
<AdminPlayerDialog :show="showPlayerDialog" :title="playerDialogTitle" :buttons="playerDialogButtons" <AdminPlayerDialog v-if="showPlayerDialog" :title="playerDialogTitle" :buttons="playerDialogButtons"
:player="playerDialogPlayer" @close="showPlayerDialog = false" @submit="playerDialogSubmit" /> :player="playerDialogPlayer" @close="showPlayerDialog = false" @submit="playerDialogSubmit" />
</div> </div>
</template> </template>