[Vuejs]-How to set focus to Vue3 Typescript app to input element on Bootstrap modal when opened

0👍

In case someone went to the same issue

here’s my solution

<script setup lang="ts">
import { ref, watch } from 'vue'

const modal = ref<boolean>(false)
const btn = ref<HTMLButtonElement>()

watch(modal, (newVal: boolean) => {
  if (newVal==true) {
    setTimeout(() => {
      btn.value!.focus()
    }, 100)
  }
})
</script>

Leave a comment