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 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-17 08:43:48 +01:00
parent 1ecf2f60f0
commit 50fdee05ed
+13 -5
View File
@@ -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;
}
/**