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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view password functionality to login form #4714

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions app/javascript/controllers/password_visibility_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static targets = ["password", "icon"];

toggle() {
const isPasswordVisible = this.passwordTarget.type === "text";

this.passwordTarget.type = isPasswordVisible ? "password" : "text";
this.iconTarget.classList.toggle("fa-eye", !isPasswordVisible);
this.iconTarget.classList.toggle("fa-eye-slash", isPasswordVisible);
}
}
23 changes: 21 additions & 2 deletions app/views/users/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<style>
.password-input-wrapper {
position: relative;
}

.toggle-password {
position: absolute;
right: 10px;
top: 70%;
transform: translateY(-50%);
cursor: pointer;
color: #999;
}
</style>
<%= render partial: "shared/flash" %>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="login-box">
Expand All @@ -11,8 +25,13 @@
<div class="form-inputs">
<%= f.input :email, autofocus: true %>
</div>
<div class="form-inputs">
<%= f.input :password, autofocus: true %>
<div class="form-inputs" data-controller="password-visibility">
<div class="password-input-wrapper">
<%= f.input :password, autofocus: true, input_html: { data: { password_visibility_target: 'password' } } %>
<span class="toggle-password">
<i class="fas fa-eye-slash" data-action="click->password-visibility#toggle" data-password-visibility-target="icon"></i>
</span>
</div>
</div>
<div class="col-12 text-center">
<%= f.button :submit, "Log in", class: "btn btn-primary btn-block" %>
Expand Down