-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
TextWidget.tsx
55 lines (50 loc) · 1.2 KB
/
TextWidget.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from 'react';
import FormControl from '@material-ui/core/FormControl';
import TextField from '@material-ui/core/TextField';
import { WidgetProps } from '@rjsf/core';
const TextWidget = ({
id,
required,
readonly,
disabled,
label,
value,
onChange,
onBlur,
onFocus,
autofocus,
options,
schema,
}: WidgetProps) => {
const _onChange = ({
target: { value },
}: React.ChangeEvent<HTMLInputElement>) =>
onChange(value === '' ? options.emptyValue : value);
const _onBlur = ({ target: { value } }: React.FocusEvent<HTMLInputElement>) =>
onBlur(id, value);
const _onFocus = ({
target: { value },
}: React.FocusEvent<HTMLInputElement>) => onFocus(id, value);
return (
<FormControl
fullWidth={true}
//error={!!rawErrors}
required={required}
>
<TextField
id={id}
label={label || schema.title}
autoFocus={autofocus}
required={required}
disabled={disabled || readonly}
name={name}
type={schema.type as string}
value={value ? value : ''}
onChange={_onChange}
onBlur={_onBlur}
onFocus={_onFocus}
/>
</FormControl>
);
};
export default TextWidget;