Skip to content

Commit 275ede6

Browse files
committed
add reveal button in password fields
1 parent dd7d401 commit 275ede6

File tree

5 files changed

+62
-25
lines changed

5 files changed

+62
-25
lines changed

frontend/src/templates.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@import url("./components/Footer/Footer.module.css");
1919
@import url("./components/PageHeading/PageHeading.module.css");
2020

21+
@import url("../node_modules/@vector-im/compound-web/src/components/Form/Controls/Action/Action.module.css");
22+
2123
.cpd-text-body-lg-regular {
2224
font: var(--cpd-font-body-lg-regular);
2325
letter-spacing: var(--cpd-font-letter-spacing-body-lg);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% import "components/icon.html" as icon %}
2+
{% import "components/field.html" as field %}
3+
4+
{% macro password_field(input_attributes, input_autocomplete="password", class="") %}
5+
<div class="password-field-container">
6+
<input {{ input_attributes }} class="cpd-text-control" type="password" autocomplete="{{input_autocomplete}}" required />
7+
<button type="button" class="action" onclick="togglePasswordVisibility(this)">
8+
{{ icon.visibility_off() }}
9+
</button>
10+
</div>
11+
12+
13+
14+
<script>
15+
function togglePasswordVisibility(button) {
16+
const input = button.previousElementSibling;
17+
if (input.type === "password") {
18+
input.type = "text";
19+
button.innerHTML = `{{ icon.visibility_on() }}`;
20+
//todo translate this
21+
button.setAttribute('aria-label', 'Hide');
22+
} else {
23+
input.type = "password";
24+
button.innerHTML = `{{ icon.visibility_off() }}`;
25+
//todo translate this
26+
button.setAttribute('aria-label', 'Show');
27+
}
28+
}
29+
</script>
30+
31+
{% endmacro %}

templates/pages/login.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{% extends "base.html" %}
1010

1111
{% from "components/idp_brand.html" import logo %}
12+
{% from "components/password_field.html" import password_field %}
1213

1314
{% block content %}
1415
<form method="POST" class="flex flex-col gap-10">
@@ -52,11 +53,11 @@ <h1 class="title">{{ _("mas.login.headline") }}</h1>
5253
{% endcall %}
5354
{% endif %}
5455

55-
{% if features.password_login %}
56+
{% if features.password_login %}
5657
{% call(f) field.field(label=_("common.password"), name="password", form_state=form) %}
57-
<input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="password" required />
58+
<!-- <input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="password" required /> -->
59+
{{ password_field(input_attributes=field.attributes(f), input_autocomplete="password") }}
5860
{% endcall %}
59-
6061
{% if features.account_recovery %}
6162
{{ button.link_text(text=_("mas.login.forgot_password"), href="/recover", class="self-center") }}
6263
{% endif %}

templates/pages/register/password.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
{% extends "base.html" %}
1010

11+
{% from "components/password_field.html" import password_field %}
12+
1113
{% block content %}
1214
<header class="page-heading">
1315
<div class="icon">
@@ -40,13 +42,14 @@ <h1 class="title">{{ _("mas.register.create_account.heading") }}</h1>
4042
{% endcall %}
4143

4244
{% call(f) field.field(label=_("common.password"), name="password", form_state=form) %}
43-
<input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required />
45+
<!--<input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required /> -->
46+
{{ password_field(input_attributes=field.attributes(f), input_autocomplete="new-password") }}
4447
{% endcall %}
45-
48+
4649
{% call(f) field.field(label=_("common.password_confirm"), name="password_confirm", form_state=form) %}
47-
<input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required />
50+
<!--<input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required /> -->
51+
{{ password_field(input_attributes=field.attributes(f), input_autocomplete="new-password") }}
4852
{% endcall %}
49-
5053
{% if branding.tos_uri %}
5154
{% call(f) field.field(label=_("mas.register.terms_of_service", tos_uri=branding.tos_uri), name="accept_terms", form_state=form, inline=true, class="my-4") %}
5255
<div class="cpd-form-inline-field-control">

translations/en.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
},
1111
"continue": "Continue",
1212
"@continue": {
13-
"context": "form_post.html:25:28-48, pages/consent.html:57:28-48, pages/device_consent.html:124:13-33, pages/device_link.html:40:26-46, pages/login.html:68:30-50, pages/reauth.html:32:28-48, pages/recovery/start.html:38:26-46, pages/register/password.html:74:26-46, pages/register/steps/display_name.html:43:28-48, pages/register/steps/registration_token.html:41:28-48, pages/register/steps/verify_email.html:51:26-46, pages/sso.html:37:28-48"
13+
"context": "form_post.html:25:28-48, pages/consent.html:57:28-48, pages/device_consent.html:124:13-33, pages/device_link.html:40:26-46, pages/login.html:69:30-50, pages/reauth.html:32:28-48, pages/recovery/start.html:38:26-46, pages/register/password.html:77:26-46, pages/register/steps/display_name.html:43:28-48, pages/register/steps/registration_token.html:41:28-48, pages/register/steps/verify_email.html:51:26-46, pages/sso.html:37:28-48"
1414
},
1515
"create_account": "Create Account",
1616
"@create_account": {
17-
"context": "pages/login.html:94:33-59, pages/upstream_oauth2/do_register.html:191:26-52"
17+
"context": "pages/login.html:95:33-59, pages/upstream_oauth2/do_register.html:191:26-52"
1818
},
1919
"sign_in": "Sign in",
2020
"@sign_in": {
@@ -79,7 +79,7 @@
7979
},
8080
"email_address": "Email address",
8181
"@email_address": {
82-
"context": "pages/recovery/start.html:34:33-58, pages/register/password.html:38:33-58, pages/upstream_oauth2/do_register.html:114:37-62"
82+
"context": "pages/recovery/start.html:34:33-58, pages/register/password.html:40:33-58, pages/upstream_oauth2/do_register.html:114:37-62"
8383
},
8484
"loading": "Loading…",
8585
"@loading": {
@@ -91,15 +91,15 @@
9191
},
9292
"password": "Password",
9393
"@password": {
94-
"context": "pages/login.html:56:37-57, pages/reauth.html:28:35-55, pages/register/password.html:42:33-53"
94+
"context": "pages/login.html:57:37-57, pages/reauth.html:28:35-55, pages/register/password.html:44:33-53"
9595
},
9696
"password_confirm": "Confirm password",
9797
"@password_confirm": {
98-
"context": "pages/register/password.html:46:33-61"
98+
"context": "pages/register/password.html:49:33-61"
9999
},
100100
"username": "Username",
101101
"@username": {
102-
"context": "pages/login.html:50:37-57, pages/register/index.html:30:35-55, pages/register/password.html:34:33-53, pages/upstream_oauth2/do_register.html:101:35-55, pages/upstream_oauth2/do_register.html:106:39-59"
102+
"context": "pages/login.html:51:37-57, pages/register/index.html:30:35-55, pages/register/password.html:36:33-53, pages/upstream_oauth2/do_register.html:101:35-55, pages/upstream_oauth2/do_register.html:106:39-59"
103103
}
104104
},
105105
"error": {
@@ -419,43 +419,43 @@
419419
"login": {
420420
"call_to_register": "Don't have an account yet?",
421421
"@call_to_register": {
422-
"context": "pages/login.html:90:13-44"
422+
"context": "pages/login.html:91:13-44"
423423
},
424424
"continue_with_provider": "Continue with %(provider)s",
425425
"@continue_with_provider": {
426-
"context": "pages/login.html:81:15-67, pages/register/index.html:53:15-67",
426+
"context": "pages/login.html:82:15-67, pages/register/index.html:53:15-67",
427427
"description": "Button to log in with an upstream provider"
428428
},
429429
"description": "Please sign in to continue:",
430430
"@description": {
431-
"context": "pages/login.html:29:29-55"
431+
"context": "pages/login.html:30:29-55"
432432
},
433433
"forgot_password": "Forgot password?",
434434
"@forgot_password": {
435-
"context": "pages/login.html:61:35-65",
435+
"context": "pages/login.html:62:35-65",
436436
"description": "On the login page, link to the account recovery process"
437437
},
438438
"headline": "Sign in",
439439
"@headline": {
440-
"context": "pages/login.html:28:31-54"
440+
"context": "pages/login.html:29:31-54"
441441
},
442442
"link": {
443443
"description": "Linking your <span class=\"break-keep text-links\">%(provider)s</span> account",
444444
"@description": {
445-
"context": "pages/login.html:24:29-75"
445+
"context": "pages/login.html:25:29-75"
446446
},
447447
"headline": "Sign in to link",
448448
"@headline": {
449-
"context": "pages/login.html:22:31-59"
449+
"context": "pages/login.html:23:31-59"
450450
}
451451
},
452452
"no_login_methods": "No login methods available.",
453453
"@no_login_methods": {
454-
"context": "pages/login.html:100:11-42"
454+
"context": "pages/login.html:101:11-42"
455455
},
456456
"username_or_email": "Username or Email",
457457
"@username_or_email": {
458-
"context": "pages/login.html:46:37-69"
458+
"context": "pages/login.html:47:37-69"
459459
}
460460
},
461461
"navbar": {
@@ -613,7 +613,7 @@
613613
"register": {
614614
"call_to_login": "Already have an account?",
615615
"@call_to_login": {
616-
"context": "pages/register/index.html:59:35-66, pages/register/password.html:77:33-64",
616+
"context": "pages/register/index.html:59:35-66, pages/register/password.html:80:33-64",
617617
"description": "Displayed on the registration page to suggest to log in instead"
618618
},
619619
"continue_with_email": "Continue with email address",
@@ -627,12 +627,12 @@
627627
},
628628
"heading": "Create an account",
629629
"@heading": {
630-
"context": "pages/register/index.html:21:29-69, pages/register/password.html:18:27-67"
630+
"context": "pages/register/index.html:21:29-69, pages/register/password.html:20:27-67"
631631
}
632632
},
633633
"terms_of_service": "I agree to the <a href=\"%s\" data-kind=\"primary\" class=\"cpd-link\">Terms and Conditions</a>",
634634
"@terms_of_service": {
635-
"context": "pages/register/password.html:51:35-95, pages/upstream_oauth2/do_register.html:179:35-95"
635+
"context": "pages/register/password.html:54:35-95, pages/upstream_oauth2/do_register.html:179:35-95"
636636
}
637637
},
638638
"registration_token": {

0 commit comments

Comments
 (0)