Skip to content

#2466 Added Eye Icon for Revealing and Hiding Passwords #2482

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

Closed
wants to merge 2 commits into from
Closed
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
Binary file added client/images/eye-close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/images/eye-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 25 additions & 9 deletions client/modules/User/components/LoginForm.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Form, Field } from 'react-final-form';
import { useDispatch } from 'react-redux';
import Button from '../../../common/Button';
import { validateLogin } from '../../../utils/reduxFormUtils';
import { validateAndLoginUser } from '../actions';
import eyeClose from '../../../images/eye-close.png';
import eyeOpen from '../../../images/eye-open.png';

function LoginForm() {
const { t } = useTranslation();
Expand All @@ -14,6 +16,12 @@ function LoginForm() {
return dispatch(validateAndLoginUser(formProps));
}

const [showPassword, setShowPassword] = useState(false);

const handleShow = () => {
setShowPassword((prev) => !prev);
};

return (
<Form
fields={['email', 'password']}
Expand Down Expand Up @@ -48,14 +56,22 @@ function LoginForm() {
<label htmlFor="password" className="form__label">
{t('LoginForm.Password')}
</label>
<input
className="form__input"
aria-label={t('LoginForm.PasswordARIA')}
type="password"
id="password"
autoComplete="current-password"
{...field.input}
/>
<div className="password_form">
<input
className="form__input"
aria-label={t('LoginForm.PasswordARIA')}
type={showPassword ? 'text' : 'password'}
id="password"
autoComplete="current-password"
{...field.input}
/>
<button className="eye_button" onClick={handleShow}>
<img
src={showPassword ? eyeClose : eyeOpen}
alt="eye-logo"
/>
</button>
</div>
{field.meta.touched && field.meta.error && (
<span className="form-error">{field.meta.error}</span>
)}
Expand Down
60 changes: 44 additions & 16 deletions client/modules/User/components/SignupForm.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Form, Field } from 'react-final-form';
import { useDispatch } from 'react-redux';
import { validateSignup } from '../../../utils/reduxFormUtils';
import { validateAndSignUpUser } from '../actions';
import Button from '../../../common/Button';
import apiClient from '../../../utils/apiClient';
import eyeClose from '../../../images/eye-close.png';
import eyeOpen from '../../../images/eye-open.png';

function asyncValidate(fieldToValidate, value) {
if (!value || value.trim().length === 0)
Expand Down Expand Up @@ -38,6 +41,10 @@ function SignupForm() {
function onSubmit(formProps) {
return dispatch(validateAndSignUpUser(formProps));
}
const [showPassword, setShowPassword] = useState(false);
const handleShow = () => {
setShowPassword((prev) => !prev);
};

return (
<Form
Expand Down Expand Up @@ -93,22 +100,43 @@ function SignupForm() {
</Field>
<Field name="password">
{(field) => (
<p className="form__field">
<label htmlFor="password" className="form__label">
{t('SignupForm.Password')}
</label>
<input
className="form__input"
aria-label={t('SignupForm.PasswordARIA')}
type="password"
id="password"
autoComplete="new-password"
{...field.input}
/>
{field.meta.touched && field.meta.error && (
<span className="form-error">{field.meta.error}</span>
)}
</p>
<div style={{ position: 'relative' }}>
<p className="form__field">
<label htmlFor="password" className="form__label">
{t('SignupForm.Password')}
</label>
<div className="password_form">
<input
className="form__input"
aria-label={t('SignupForm.PasswordARIA')}
type={showPassword ? 'text' : 'password'}
id="password"
autoComplete="new-password"
{...field.input}
/>
<button
type="button"
className="eye_button"
onClick={handleShow}
style={{
fontSize: '25px',
position: 'absolute',
top: '38%',
right: '2px',
paddingTop: '4.5px'
}}
>
<img
src={showPassword ? eyeClose : eyeOpen}
alt="eye-logo"
/>
</button>
</div>
{field.meta.touched && field.meta.error && (
<span className="form-error">{field.meta.error}</span>
)}
</p>
</div>
)}
</Field>
<Field name="confirmPassword">
Expand Down
21 changes: 21 additions & 0 deletions client/styles/components/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@
margin-right: auto;
}

.password_form {
position: relative;
}

.eye_button {
position: absolute;
top: 50%;
right: 10px;
transform: translateY(-50%);
background: none;
border: none;
padding: 0;
cursor: pointer;
}

.eye_button img {
width: 24px;
height: auto;
}


// .form [type="submit"] {
// @extend %button;
// padding: #{8 / $base-font-size}rem #{25 / $base-font-size}rem;
Expand Down