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

toggle password visibility #1700

Merged
merged 4 commits into from
May 26, 2024
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
28 changes: 25 additions & 3 deletions src/components/Account/Login/Login.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import validationSchema from './validationSchema';
import { login } from './Login.actions';
import messages from './Login.messages';
import './Login.css';
import InputAdornment from '@material-ui/core/InputAdornment';
import IconButton from '@material-ui/core/IconButton';
import { Visibility, VisibilityOff } from '@material-ui/icons';

export class Login extends Component {
static propTypes = {
Expand All @@ -32,7 +35,8 @@ export class Login extends Component {

state = {
isLogging: false,
loginStatus: {}
loginStatus: {},
isPasswordVisible: false
};

handleSubmit = values => {
Expand All @@ -47,9 +51,14 @@ export class Login extends Component {
.catch(loginStatus => this.setState({ loginStatus }))
.finally(() => this.setState({ isLogging: false }));
};
togglePasswordVisibility = () => {
this.setState(prevState => ({
isPasswordVisible: !prevState.isPasswordVisible
}));
};

render() {
const { isLogging, loginStatus } = this.state;
const { isLogging, loginStatus, isPasswordVisible } = this.state;
const {
intl,
isDialogOpen,
Expand Down Expand Up @@ -95,8 +104,21 @@ export class Login extends Component {
<TextField
error={errors.password}
label={intl.formatMessage(messages.password)}
type="password"
type={isPasswordVisible ? 'text' : 'password'}
name="password"
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton onClick={this.togglePasswordVisibility}>
{isPasswordVisible ? (
<Visibility />
) : (
<VisibilityOff />
)}
</IconButton>
</InputAdornment>
)
}}
onChange={handleChange}
/>
<DialogActions>
Expand Down
10 changes: 6 additions & 4 deletions src/components/UI/FormItems/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ const propTypes = {
PropTypes.bool,
PropTypes.string,
PropTypes.number
])
]),
InputProps: PropTypes.object
};

const defaultProps = {
className: '',
error: false
error: false,
InputProps: null
};

const TextField = ({ className, error, ...props }) => (
const TextField = ({ className, error, InputProps, ...props }) => (
<FormControl className={className} error={!!error}>
<MUITextField error={!!error} {...props} />
<MUITextField error={!!error} {...props} InputProps={InputProps} />
{error && <FormHelperText>{error}</FormHelperText>}
</FormControl>
);
Expand Down
Loading