web/flows: fix focus being continuously forced to the input

closes #2692

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-04-08 18:26:39 +02:00
parent d9e4219d70
commit 7a44d5768a
2 changed files with 643 additions and 782 deletions

View File

@ -46,7 +46,17 @@ export class PasswordStage extends BaseStage<PasswordChallenge, PasswordChalleng
if (!this.input) { if (!this.input) {
return; return;
} }
if (document.activeElement === this.input) { // Because activeElement behaves differently with shadow dom
// we need to recursively check
const rootEl = document.activeElement;
const isActive = (el: Element | null): boolean => {
if (!rootEl) return false;
if (!("shadowRoot" in rootEl)) return false;
if (rootEl.shadowRoot === null) return false;
if (rootEl.shadowRoot.activeElement === el) return true;
return isActive(rootEl.shadowRoot.activeElement);
};
if (isActive(this.input)) {
this.cleanup(); this.cleanup();
} }
this.input.focus(); this.input.focus();

File diff suppressed because it is too large Load Diff