blob: 285d626e5373052f6ccd958bccc18ca3ec35a989 (
plain)
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
|
import * as React from 'react';
import {
Component, InputHTMLAttributes,
SyntheticEvent
} from 'react';
export interface SubmitInputProps extends InputHTMLAttributes<HTMLInputElement> {
initialValue?: string;
onSubmitValue: (value: string) => void;
}
export interface SubmitInputState {
value: string;
}
export class SubmitInput extends Component<SubmitInputProps, SubmitInputState> {
state: SubmitInputState = {
value: ''
};
constructor(props: SubmitInputProps) {
super(props);
this.state.value = props.initialValue || '';
}
onSubmit = (event: SyntheticEvent<any>) => {
event.preventDefault();
this.props.onSubmitValue(this.state.value);
};
render() {
const {initialValue, onSubmitValue, ...props} = this.props;
return <form onSubmit={this.onSubmit}>
<input type="text" value={this.state.value}
{...props}
onChange={event => this.setState({value: event.currentTarget.value})}/>
</form>;
}
}
|