-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #618 from cedarcode/jt--show_password
Add button to show password on password fields
- Loading branch information
Showing
10 changed files
with
65 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,3 +221,7 @@ body { | |
#butInstall { | ||
padding-left: 0px; | ||
} | ||
|
||
.show-password-button { | ||
margin-right: -20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static targets = ["password", "icon"]; | ||
|
||
toggle() { | ||
if (this.passwordTarget.type === "password") { | ||
this.passwordTarget.type = "text"; | ||
this.iconTarget.innerHTML = "visibility_off"; | ||
} else { | ||
this.passwordTarget.type = "password"; | ||
this.iconTarget.innerHTML = "visibility"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="mdc-text-field mdc-text-field--filled <%='mdc-text-field--invalid mdc-text-field--with-trailing-icon' if resource.errors[field].any? %>" data-controller="textfield show-password"> | ||
<span class="mdc-text-field__ripple"></span> | ||
<%= f.label field, label_text, class: "mdc-floating-label" %> | ||
<%= f.password_field field, class: "mdc-text-field__input", required:, autofocus: true, autocomplete:, data: { show_password_target: "password" } %> | ||
<button type="button" class="mdc-button show-password-button" data-action="show-password#toggle"> | ||
<span class="material-icons" data-show-password-target="icon">visibility</span> | ||
</button> | ||
<%= render 'shared/invalid_icon', resource:, field: %> | ||
<div class="mdc-line-ripple"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module PasswordHelpers | ||
def password_visibility_toggle_test(label_text) | ||
container = find("li", text: label_text, match: :prefer_exact) | ||
|
||
within(container) do | ||
find(".show-password-button").click | ||
assert_selector "input[type='text']" | ||
find(".show-password-button").click | ||
assert_selector "input[type='password']" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
class UserTest < ApplicationSystemTestCase | ||
include ActionMailer::TestHelper | ||
include PasswordHelpers | ||
|
||
test "can sign up" do | ||
user = create :user | ||
|
@@ -34,6 +35,8 @@ class UserTest < ApplicationSystemTestCase | |
fill_in "Correo electrónico", with: '[email protected]' | ||
fill_in "Nueva contraseña", with: 'alice123' | ||
fill_in "Confirma tu nueva contraseña", with: 'alice123' | ||
password_visibility_toggle_test("Nueva contraseña") | ||
password_visibility_toggle_test("Confirma tu nueva contraseña") | ||
click_on "Registrarte" | ||
|
||
assert_current_path root_path | ||
|
@@ -70,6 +73,7 @@ class UserTest < ApplicationSystemTestCase | |
visit edit_user_password_path(reset_password_token: user.send_reset_password_instructions) | ||
|
||
fill_in "Nueva contraseña", with: "new_password" | ||
password_visibility_toggle_test("Nueva contraseña") | ||
click_on "Restablecer contraseña" | ||
assert_text 'Tu contraseña fue modificada correctamente. Has iniciado sesión.' | ||
|
||
|
@@ -103,6 +107,7 @@ class UserTest < ApplicationSystemTestCase | |
|
||
fill_in "Correo electrónico", with: user.email | ||
fill_in "Contraseña", with: user.password | ||
password_visibility_toggle_test("Contraseña") | ||
click_on "Ingresar" | ||
|
||
assert_current_path(root_path) | ||
|
@@ -155,6 +160,9 @@ class UserTest < ApplicationSystemTestCase | |
fill_in "Nueva contraseña", with: "new_password" | ||
fill_in "Confirma tu nueva contraseña", with: "new_password" | ||
fill_in "Contraseña actual", with: user.password | ||
password_visibility_toggle_test("Nueva contraseña") | ||
password_visibility_toggle_test("Confirma tu nueva contraseña") | ||
password_visibility_toggle_test("Contraseña actual") | ||
fill_in "Correo electrónico", with: "new_#{user.email}" | ||
click_on "Guardar" | ||
assert_text "Actualizaste tu cuenta correctamente." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters