Skip to content

Commit 9f20778

Browse files
committed
Added Input wrapper
1 parent 00724c4 commit 9f20778

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ with Final Form
99

1010
### Available fields
1111
```jsx
12-
import {TextField, Checkbox, Radio, Select} from 'final-form-material-ui';
12+
import {TextField, Checkbox, Radio, Select, Input} from 'final-form-material-ui';
1313
```
1414

1515
##### TextField
@@ -28,6 +28,29 @@ import {TextField} from 'final-form-material-ui';
2828
/>
2929
```
3030

31+
##### Input
32+
```jsx
33+
import React from 'react';
34+
import {Field} from 'react-final-form';
35+
import {Input} from 'final-form-material-ui';
36+
import InputAdornment from '@material-ui/core/InputAdornment';
37+
38+
<Field
39+
name="password"
40+
component={Input}
41+
className="input"
42+
type="password"
43+
placeholder="Password"
44+
endAdornment={
45+
<InputAdornment position="end">
46+
<Link className="inputLink" to="/forgot">
47+
Forgot password?
48+
</Link>
49+
</InputAdornment>
50+
}
51+
/>
52+
```
53+
3154
##### Select
3255
Use can pass any props from [`Select docs`](https://material-ui.com/api/select/) to `Field`.
3356
Additional props for `Field`:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "final-form-material-ui",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "A set of wrapper components to facilitate using Material UI with Final Form",
55
"main": "./dist/final-form-material-ui.min.js",
66
"author": "Igor Golovin <[email protected]>",

src/Input.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as React from 'react';
2+
import {FieldRenderProps} from 'react-final-form';
3+
import Input from '@material-ui/core/Input';
4+
import FormHelperText from '@material-ui/core/FormHelperText';
5+
6+
7+
const InputWrapper: React.SFC<FieldRenderProps> = ({input: {name, onChange, value, ...restInput}, meta, ...rest}) => {
8+
const showError = ((meta.submitError && !meta.dirtySinceLastSubmit) || meta.error) && meta.touched;
9+
10+
return (
11+
<>
12+
<Input
13+
{...rest}
14+
name={name}
15+
error={showError}
16+
inputProps={restInput}
17+
onChange={onChange}
18+
value={value}
19+
/>
20+
21+
{showError &&
22+
<FormHelperText>
23+
{meta.error || meta.submitError}
24+
</FormHelperText>
25+
}
26+
</>
27+
);
28+
};
29+
30+
export default InputWrapper;

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import TextField from './TextField';
22
import Checkbox from './Checkbox';
33
import Radio from './Radio';
44
import Select from './Select';
5+
import Input from './Input';
56

67

7-
export {TextField, Checkbox, Radio, Select};
8+
export {TextField, Checkbox, Radio, Select, Input};

0 commit comments

Comments
 (0)