-
@@ -340,6 +363,7 @@
const reveal = function() {
password.type = 'text';
+ toggle.setAttribute('aria-pressed', 'true');
if (icon) {
icon.classList.remove('fa-eye');
icon.classList.add('fa-eye-slash');
@@ -348,13 +372,13 @@
const conceal = function() {
password.type = 'password';
+ toggle.setAttribute('aria-pressed', 'false');
if (icon) {
icon.classList.remove('fa-eye-slash');
icon.classList.add('fa-eye');
}
};
- // Press and hold to reveal; release (or leave/blur) to hide.
toggle.addEventListener('mousedown', function(e) {
e.preventDefault();
reveal();
@@ -366,11 +390,12 @@
toggle.addEventListener('touchstart', function(e) {
e.preventDefault();
reveal();
- }, { passive: false });
+ }, {
+ passive: false
+ });
toggle.addEventListener('touchend', conceal);
toggle.addEventListener('touchcancel', conceal);
- // Keyboard: reveal while Space/Enter is held, hide on release/blur.
toggle.addEventListener('keydown', function(e) {
if (e.key === ' ' || e.key === 'Enter' || e.key === 'Spacebar') {
e.preventDefault();
@@ -384,7 +409,6 @@
});
toggle.addEventListener('blur', conceal);
- // Safety net: never leave the password visible on tab-away.
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
conceal();