show/hide password button
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// Toggle password visibility so users can check for typos, especially on mobile.
|
||||
document.querySelectorAll(".password-toggle").forEach(function (button) {
|
||||
button.addEventListener("pointerdown", function (event) {
|
||||
// Toggle on press (not click) for an instant response. preventScroll avoids
|
||||
// a scroll-to-input animation that makes rapid toggling feel laggy, and
|
||||
// keeping focus on the input keeps the mobile keyboard open.
|
||||
event.preventDefault();
|
||||
var input = document.getElementById(button.getAttribute("data-toggle-for"));
|
||||
if (!input) return;
|
||||
var showing = input.type === "text";
|
||||
input.type = showing ? "password" : "text";
|
||||
button.textContent = showing ? "Show" : "Hide";
|
||||
button.setAttribute("aria-label", showing ? "Show password" : "Hide password");
|
||||
input.focus({ preventScroll: true });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user