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

fix#115 : Add isSecure property #120

Merged
merged 4 commits into from
Oct 28, 2020
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ export default class App extends Component {
<td>false</td>
<td>Restrict input to only numbers.</td>
</tr>
<tr>
<td>isSecure</td>
<td>boolean</td>
<td>false</td>
<td>false</td>
<td>Masks input characters.</td>
</tr>
</table>

## Breaking changes when porting to v1.0.0
Expand Down
15 changes: 15 additions & 0 deletions src/demo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Demo extends Component {
isDisabled: false,
hasErrored: false,
isInputNum: false,
isSecure: false,
minLength: 0,
maxLength: 40,
};
Expand Down Expand Up @@ -64,6 +65,7 @@ class Demo extends Component {
isDisabled,
hasErrored,
isInputNum,
isSecure,
minLength,
maxLength,
} = this.state;
Expand Down Expand Up @@ -155,6 +157,18 @@ class Demo extends Component {
isInputNum
</label>
</div>
<div className="side-bar__segment">
<label htmlFor="isSecure">
<input
id="isSecure"
name="isSecure"
type="checkbox"
checked={isSecure}
onChange={this.handleCheck}
/>
isSecure
</label>
</div>
<div className="side-bar__segment side-bar__segment--bottom">
<a href="https://github.com/devfolioco/react-otp-input">
Documentation and Source
Expand All @@ -175,6 +189,7 @@ class Demo extends Component {
onChange={this.handleOtpChange}
separator={<span>{separator}</span>}
isInputNum={isInputNum}
isSecure={isSecure}
shouldAutoFocus
value={otp}
/>
Expand Down
15 changes: 13 additions & 2 deletions src/lib/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Props = {
isInputNum?: boolean,
value?: string,
className?: string,
isSecure?: boolean
};

type State = {
Expand Down Expand Up @@ -69,6 +70,12 @@ class SingleOtpInput extends PureComponent<*> {

getClasses = (...classes) =>
classes.filter(c => !isStyleObject(c) && c !== false).join(' ');

getType = () => {
if (this.props.isSecure) return 'password'
if (this.props.isInputNum) return 'tel'
return 'text'
}

render() {
const {
Expand All @@ -86,6 +93,7 @@ class SingleOtpInput extends PureComponent<*> {
isInputNum,
value,
className,
isSecure,
...rest
} = this.props;

Expand All @@ -110,7 +118,7 @@ class SingleOtpInput extends PureComponent<*> {
isDisabled && disabledStyle,
hasErrored && errorStyle
)}
type={isInputNum ? 'tel' : 'text'}
type={this.getType()}
maxLength="1"
ref={input => {
this.input = input;
Expand All @@ -132,6 +140,7 @@ class OtpInput extends Component<Props, State> {
isDisabled: false,
shouldAutoFocus: false,
value: '',
isSecure:false
};

state = {
Expand Down Expand Up @@ -287,7 +296,8 @@ class OtpInput extends Component<Props, State> {
errorStyle,
shouldAutoFocus,
isInputNum,
className,
isSecure,
className
} = this.props;
const otp = this.getOtpValue();
const inputs = [];
Expand Down Expand Up @@ -318,6 +328,7 @@ class OtpInput extends Component<Props, State> {
errorStyle={errorStyle}
shouldAutoFocus={shouldAutoFocus}
isInputNum={isInputNum}
isSecure={isSecure}
className={className}
/>
);
Expand Down