Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add password visibility toggle #15605

Merged
merged 9 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move UI element definitions to scala
  • Loading branch information
joeyksclark committed Jun 26, 2024
commit 91b7295d0959a88d402dd3e2eb5f756b888cbe36
11 changes: 6 additions & 5 deletions modules/web/src/main/ui/AuthUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ body { margin-top: 45px; }
"policy" -> trans.site.agreementPolicy()
)

private def formFields(username: Field, password: Field, email: Option[Field], register: Boolean)(using
Context
) =
private def formFields(username: Field, password: Field, email: Option[Field], register: Boolean)(using Context) =
frag(
form3.group(
username,
Expand All @@ -350,8 +348,11 @@ body { margin-top: 45px; }
form3.input(f)(autofocus, required, autocomplete := "username"),
register.option(p(cls := "error username-exists none")(trans.site.usernameAlreadyUsed()))
),
form3.passwordModified(password, trans.site.password())(
autocomplete := (if register then "new-password" else "current-password")
div(cls := "password-wrapper")(
form3.passwordModified(password, trans.site.password())(
autocomplete := (if register then "new-password" else "current-password")
),
button(cls := "show-hide-password", title := "Show/hide password")("Joey")
),
register.option(form3.passwordComplexityMeter(trans.site.newPasswordStrength())),
email.map: email =>
Expand Down
1 change: 0 additions & 1 deletion ui/bits/css/_auth.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
cursor: pointer;
Expand Down
12 changes: 5 additions & 7 deletions ui/bits/src/bits.login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function loginStart() {
}

function signupStart() {
passwordShowHide();
const $form = $('#signup-form'),
$exists = $form.find('.username-exists'),
$username = $form.find('input[name="username"]').on('change keyup paste', () => {
Expand Down Expand Up @@ -112,13 +113,10 @@ function signupStart() {
}

function passwordShowHide() {
$('#form3-password').each(function (this: HTMLElement) {
const $input = $(this);
$input.wrap('<div class="password-wrapper"></div>');
const $wrapper = $input.parent();
const $button = $('<button class="show-hide-password" title="Show/hide password">Joey</button>').appendTo(
$wrapper,
);
$('.password-wrapper').each(function (this: HTMLElement) {
const $wrapper = $(this);
const $input = $wrapper.find('input[type="password"], input[type="text"]');
const $button = $wrapper.find('.show-hide-password');
$button.on('click', function (e: Event) {
e.preventDefault();
const type = $input.attr('type') === 'password' ? 'text' : 'password';
Expand Down