From: Tim Düsterhus Date: Wed, 17 Mar 2021 13:04:15 +0000 (+0100) Subject: Maintain focus of the password input when adding the password visibility button X-Git-Tag: 5.4.0_Alpha_1~143^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8988202f508f3d98aed8f213da006332bb44f091;p=GitHub%2FWoltLab%2FWCF.git Maintain focus of the password input when adding the password visibility button Fixes #4050 --- diff --git a/ts/WoltLabSuite/Core/Ui/Password.ts b/ts/WoltLabSuite/Core/Ui/Password.ts index b9ef3e4882..7576117fe5 100644 --- a/ts/WoltLabSuite/Core/Ui/Password.ts +++ b/ts/WoltLabSuite/Core/Ui/Password.ts @@ -28,6 +28,8 @@ function initElements(): void { function initElement(input: HTMLInputElement): void { _knownElements.add(input); + const activeElement = document.activeElement; + const inputAddon = document.createElement("div"); inputAddon.classList.add("inputAddon"); input.insertAdjacentElement("beforebegin", inputAddon); @@ -54,6 +56,10 @@ function initElement(input: HTMLInputElement): void { toggle(input, button, icon); } }); + + if (activeElement === input) { + input.focus(); + } } function toggle(input: HTMLInputElement, button: HTMLElement, icon: HTMLElement): void { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Password.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Password.js index f1f503a9da..08685dfb50 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Password.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Password.js @@ -27,6 +27,7 @@ define(["require", "exports", "tslib", "../Dom/Change/Listener", "../Language"], } function initElement(input) { _knownElements.add(input); + const activeElement = document.activeElement; const inputAddon = document.createElement("div"); inputAddon.classList.add("inputAddon"); input.insertAdjacentElement("beforebegin", inputAddon); @@ -50,6 +51,9 @@ define(["require", "exports", "tslib", "../Dom/Change/Listener", "../Language"], toggle(input, button, icon); } }); + if (activeElement === input) { + input.focus(); + } } function toggle(input, button, icon) { if (input.type === "password") {