From 79f91ebd87e42e4547adc6f2a71c0bc1f5aa6a17 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Tue, 5 Mar 2024 08:46:56 +0100 Subject: [PATCH] webmail: don't switch back focus after autocompleting address actually, this fix can reduce focus changes for more operations. withStatus is often used to show an operation in progress in the status bar, only when the operation isn't done within 1 second. we would restore focus to the element before the operation started. that was done because we disable elements sometimes (preventing duplicate form submission). for things like the autocomplete, with the tab key, which also moves focus to the next element, we don't want that focus switched back again. --- webmail/webmail.js | 2 +- webmail/webmail.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/webmail/webmail.js b/webmail/webmail.js index 64581d5..395a5a9 100644 --- a/webmail/webmail.js +++ b/webmail/webmail.js @@ -1967,7 +1967,7 @@ const withStatus = async (action, promise, disablable, noAlert) => { if (disablable) { disablable.disabled = false; } - if (origFocus && document.activeElement !== origFocus && origFocus instanceof HTMLElement) { + if (disablable && origFocus && document.activeElement !== origFocus && origFocus instanceof HTMLElement && origFocus.parentNode) { origFocus.focus(); } if (id) { diff --git a/webmail/webmail.ts b/webmail/webmail.ts index 58f51ce..9672181 100644 --- a/webmail/webmail.ts +++ b/webmail/webmail.ts @@ -902,7 +902,7 @@ const withStatus = async (action: string, promise: Promise, disablable?: D if (disablable) { disablable.disabled = false } - if (origFocus && document.activeElement !== origFocus && origFocus instanceof HTMLElement) { + if (disablable && origFocus && document.activeElement !== origFocus && origFocus instanceof HTMLElement && origFocus.parentNode) { origFocus.focus() } if (id) {