From ec1a2ba7f05980591c3654ce793c2af08bb2f3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20G=C3=B3mez?= Date: Sat, 13 Sep 2025 07:33:49 +0200 Subject: [PATCH] fix: fix message focus --- .../src/components/chat/MessageItem.vue | 16 ++- .../src/components/chat/MessagesContainer.vue | 103 +++++++++++++++--- 2 files changed, 92 insertions(+), 27 deletions(-) diff --git a/frontend-vue/src/components/chat/MessageItem.vue b/frontend-vue/src/components/chat/MessageItem.vue index f36fec6..5574e19 100644 --- a/frontend-vue/src/components/chat/MessageItem.vue +++ b/frontend-vue/src/components/chat/MessageItem.vue @@ -6,11 +6,12 @@ ]" ref="rootEl" :data-message-id="message.id" - :tabindex="tabindex || -1" + :tabindex="tabindex ?? -1" :aria-label="messageAriaLabel" role="option" @keydown="handleKeydown" @click="handleClick" + @focus="handleFocus" >
{{ message.content }} @@ -53,6 +54,7 @@ interface Props { const emit = defineEmits<{ 'open-dialog': [message: ExtendedMessage | UnsentMessage] + 'focus': [] }>() const props = withDefaults(defineProps(), { @@ -260,14 +262,6 @@ const handleDelete = async () => { } throw error } - // focus the closest message - await nextTick() - if (targetToFocus && document.contains(targetToFocus)) { - if (!targetToFocus.hasAttribute('tabindex')) targetToFocus.setAttribute('tabindex', '-1') - targetToFocus.focus() - } else { - focusFallbackToInput() - } } catch (error) { console.error('Failed to delete message:', error) @@ -358,3 +352,7 @@ const handleDelete = async () => { } } +const handleFocus = () => { + // Emit a focus event so the parent list can update its focused index + emit('focus') +} diff --git a/frontend-vue/src/components/chat/MessagesContainer.vue b/frontend-vue/src/components/chat/MessagesContainer.vue index a6c3e83..ab448b7 100644 --- a/frontend-vue/src/components/chat/MessagesContainer.vue +++ b/frontend-vue/src/components/chat/MessagesContainer.vue @@ -1,5 +1,5 @@