Skip to content

Instantly share code, notes, and snippets.

@longdog
Last active August 11, 2021 08:31
Show Gist options
  • Save longdog/4a356ad976b0654a1e506a1e793596ce to your computer and use it in GitHub Desktop.
Save longdog/4a356ad976b0654a1e506a1e793596ce to your computer and use it in GitHub Desktop.
React Bootstrap Password Control with show/hide effect
import React, { Component, PropTypes } from 'react';
import {FormControl} from 'react-bootstrap';
import styles from './PasswordField.less';
class PasswordField extends Component {
state = {
type: 'password'
};
showHide = (e) => {
e.preventDefault();
e.stopPropagation();
this.setState({
type: this.state.type === 'text' ? 'password' : 'text'
});
this.input.focus();
}
render(){
return(
<div className={styles.password} >
<FormControl type={this.state.type} {...this.props} inputRef={ref => { this.input = ref; }} />
<span className={[styles.visibility, 'flaticon-eye', this.state.type === 'text' ? styles.is_visible : styles.is_hidden].join(' ')} onClick={this.showHide}></span>
</div>
);
}
}
export default PasswordField;
@srandak
Copy link

srandak commented Feb 13, 2021

Hi, can you please share the less file too. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment