import * as React from 'react'; import { Component, InputHTMLAttributes, SyntheticEvent, } from 'react'; export interface SubmitInputProps extends InputHTMLAttributes { type?: 'text' | 'number'; initialValue?: string; name: string; onSubmitValue: (value: string) => void; focus?: boolean; disabled?: boolean; } export interface SubmitInputState { value: string; } export class SubmitInput extends Component { state: SubmitInputState = { value: '', }; constructor(props: SubmitInputProps) { super(props); this.state.value = props.initialValue ?? ''; } private onSubmit = (event: SyntheticEvent) => { event.preventDefault(); this.props.onSubmitValue(this.state.value); }; public render(): JSX.Element { return
this.setState({value: event.currentTarget.value})} onBlur={() => this.props.onSubmitValue(this.state.value)} autoFocus={this.props.focus} min={this.props.min} max={this.props.max} disabled={this.props.disabled} />
; } }