Skip to content

Commit 7313d75

Browse files
committed
fix(forms): include an option to change the FormInput type
1 parent aa55a79 commit 7313d75

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

demo/demo.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ function FormExamples() {
4343
<div className="col">
4444
<FormGroupInput name="textField2" label="Text field 2" required placeholder="Fill some value" />
4545
</div>
46+
<div className="col">
47+
<FormGroupInput name="textField3" label="Text field 3" type="number" />
48+
</div>
4649
</div>
4750

4851
<div className="row">

src/forms/FormInput.jsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import React, { useContext } from 'react';
2+
import PropTypes from 'prop-types';
23
import { FormContext, handleInputChange } from './form-helpers';
34

4-
export function FormInput({ id, name, required, placeholder }) {
5+
export function FormInput({ id, type, name, required, placeholder }) {
56
const formState = useContext(FormContext);
67

78
return (
89
<input
9-
{...{ required, name, id, placeholder }}
10+
{...{ required, name, id, placeholder, type }}
1011
className="form-control"
1112
onChange={handleInputChange.bind(null, formState)}
1213
value={formState.getValue(name) || ''}
1314
/>
1415
);
1516
}
17+
18+
FormInput.defaultProps = {
19+
type: 'text',
20+
};
21+
22+
FormInput.propTypes = {
23+
id: PropTypes.string,
24+
type: PropTypes.string,
25+
name: PropTypes.string.isRequired,
26+
placeholder: PropTypes.string,
27+
};

0 commit comments

Comments
 (0)