Skip to content

Commit

Permalink
Merge pull request #1700 from nmro184/toggle-password-visibility
Browse files Browse the repository at this point in the history
toggle password visibility
  • Loading branch information
RodriSanchez1 authored May 26, 2024
2 parents 612f116 + 1fc96f3 commit aa67328
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
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

0 comments on commit aa67328

Please sign in to comment.