Last active
August 11, 2021 08:31
-
-
Save longdog/4a356ad976b0654a1e506a1e793596ce to your computer and use it in GitHub Desktop.
React Bootstrap Password Control with show/hide effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, can you please share the less file too. Thank you!