#248 - Unfocus chat input when clicking outside
This commit is contained in:
parent
d820490b2b
commit
8910390f7b
@ -14,6 +14,7 @@
|
||||
v-model="message"
|
||||
@keypress="handleKeyPress"
|
||||
@submit="handleSubmit"
|
||||
ref="chatInput"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -21,6 +22,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref, nextTick } from 'vue'
|
||||
import { onClickOutside } from '@vueuse/core'
|
||||
import { useGameStore } from '@/stores/gameStore'
|
||||
import type { Chat } from '@/types'
|
||||
import { useZoneStore } from '@/stores/zoneStore'
|
||||
@ -33,6 +35,15 @@ const zoneStore = useZoneStore()
|
||||
const message = ref('')
|
||||
const chats = ref([] as Chat[])
|
||||
const chatWindow = ref<HTMLElement | null>(null)
|
||||
const chatInput = ref<HTMLElement | null>(null)
|
||||
|
||||
onClickOutside(chatInput, event => unfocusChat(event, chatInput.value as HTMLElement))
|
||||
|
||||
function unfocusChat(event: Event, targetElement: HTMLElement) {
|
||||
if (!(event.target instanceof Node) || !targetElement.contains(event.target)) {
|
||||
targetElement.blur();
|
||||
}
|
||||
}
|
||||
|
||||
const sendMessage = () => {
|
||||
if (!message.value.trim()) return
|
||||
|
Loading…
x
Reference in New Issue
Block a user