Skip to content

Commit

Permalink
feat(SelectUnitModal): focus search when modal open
Browse files Browse the repository at this point in the history
  • Loading branch information
rudnovd committed Apr 4, 2022
1 parent 935fa58 commit ea59692
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/SelectUnitModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<BaseDialog :show="show" size="large" @close="onClose">
<template #header>
<input
ref="searchInput"
v-model="search"
type="text"
class="search-input"
Expand Down Expand Up @@ -61,7 +62,7 @@
import BaseDialog from '@/components/base/BaseDialog.vue'
import type { Creature } from '@/models/Creature'
import { useStore } from '@/store'
import { computed, defineAsyncComponent, defineComponent, ref } from 'vue'
import { computed, defineAsyncComponent, defineComponent, onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
export default defineComponent({
Expand All @@ -79,12 +80,18 @@ export default defineComponent({
emits: ['close', 'select'],
setup(props, context) {
const { t } = useI18n()
const search = ref('')
const store = useStore()
const creatures = computed(() => store.creatures)
const towns = computed(() => store.towns)
const search = ref('')
const searchInput = ref()
onMounted(() => {
searchInput.value.focus()
})
const searchCreatures = computed(() => {
return creatures.value.filter((creature: Creature) => {
const searchText = search.value.toLowerCase()
Expand Down Expand Up @@ -130,12 +137,14 @@ export default defineComponent({
}
return {
t,
towns,
search,
creaturesByTowns,
searchCreatures,
searchInput,
t,
selectUnit,
selectFirstFounded,
onClose,
Expand Down

0 comments on commit ea59692

Please sign in to comment.