From 50fdee05edaa47903991f2f68d8daa94312632af Mon Sep 17 00:00:00 2001 From: MarekWo Date: Tue, 17 Mar 2026 08:43:48 +0100 Subject: [PATCH] fix(dm): prevent dropdown close on mouse hover, ensure name after select - Prevent mousedown on dropdown from stealing focus (which closed the dropdown before click could register on desktop) - After selecting from dropdown, override search input with the known name to guarantee correct display even if prefix match fails Co-Authored-By: Claude Opus 4.6 --- app/static/js/dm.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/static/js/dm.js b/app/static/js/dm.js index e6ece80..b63caf7 100644 --- a/app/static/js/dm.js +++ b/app/static/js/dm.js @@ -189,7 +189,13 @@ function setupEventListeners() { contactDropdown.style.display = 'block'; }); - document.addEventListener('click', (e) => { + // Prevent dropdown mousedown from stealing focus/closing dropdown + contactDropdown.addEventListener('mousedown', (e) => { + e.preventDefault(); + }); + + // Close dropdown when clicking outside the wrapper + document.addEventListener('mousedown', (e) => { if (searchWrapper && !searchWrapper.contains(e.target)) { contactDropdown.style.display = 'none'; } @@ -452,12 +458,14 @@ function createDropdownItem(name, conversationId, isUnread, contact) { /** * Handle selection from the searchable dropdown. */ -function selectConversationFromDropdown(conversationId, name) { - const input = document.getElementById('dmContactSearchInput'); +async function selectConversationFromDropdown(conversationId, name) { const dropdown = document.getElementById('dmContactDropdown'); - if (input) input.value = displayName(name); if (dropdown) dropdown.style.display = 'none'; - selectConversation(conversationId); + await selectConversation(conversationId); + // Override search input with the known name (selectConversation may not resolve it) + const input = document.getElementById('dmContactSearchInput'); + if (input && name) input.value = displayName(name); + if (name) currentRecipient = name; } /**