Сделал перемещение фокуса на поле ввода после закрытия модалки

This commit is contained in:
Ilia Miheev
2026-06-24 20:13:51 +03:00
parent 5b3c9f5fcf
commit d7846ea923
+9 -2
View File
@@ -1,11 +1,12 @@
<script setup> <script setup>
import { computed, onMounted, onUnmounted, watch } from 'vue' import { computed, onMounted, onUnmounted, watch, nextTick, ref } from 'vue'
import { useTheme } from './composables/useTheme' import { useTheme } from './composables/useTheme'
import { useQrCode } from './composables/useQrCode' import { useQrCode } from './composables/useQrCode'
import { useAppConfig } from './composables/useAppConfig' import { useAppConfig } from './composables/useAppConfig'
const config = useAppConfig() const config = useAppConfig()
const { isLightTheme, toggleTheme } = useTheme() const { isLightTheme, toggleTheme } = useTheme()
const textInputRef = ref(null)
const { const {
textInput, textInput,
@@ -34,8 +35,13 @@ function onKeydown(event) {
} }
} }
watch(showModal, (open) => { watch(showModal, async (open) => {
document.body.style.overflow = open ? 'hidden' : '' document.body.style.overflow = open ? 'hidden' : ''
if (!open) {
await nextTick()
textInputRef.value?.focus()
}
}) })
onMounted(() => { onMounted(() => {
@@ -67,6 +73,7 @@ onUnmounted(() => {
<div class="inputs"> <div class="inputs">
<textarea <textarea
ref="textInputRef"
v-model="textInput" v-model="textInput"
cols="30" cols="30"
rows="3" rows="3"