Can submit input by pressing enter

This commit is contained in:
Pierre HUBERT 2021-07-13 17:14:54 +02:00
parent 378808528e
commit 113c38daff

View File

@ -16,7 +16,7 @@ import {
IconButton, IconButton,
} from "@material-ui/core"; } from "@material-ui/core";
import { Close } from "@material-ui/icons"; import { Close } from "@material-ui/icons";
import React from "react"; import React, { FormEvent } from "react";
let cache: ApplicationDialogsProvider; let cache: ApplicationDialogsProvider;
@ -94,6 +94,7 @@ export class ApplicationDialogsProvider extends React.Component<
this.acceptConfirm = this.handleCloseConfirm.bind(this, true); this.acceptConfirm = this.handleCloseConfirm.bind(this, true);
this.rejectConfirm = this.handleCloseConfirm.bind(this, false); this.rejectConfirm = this.handleCloseConfirm.bind(this, false);
this.submitInput = this.submitInput.bind(this);
this.handleInputValueChanged = this.handleInputValueChanged.bind(this); this.handleInputValueChanged = this.handleInputValueChanged.bind(this);
this.cancelInput = this.handleCloseInput.bind(this, true); this.cancelInput = this.handleCloseInput.bind(this, true);
this.confirmInput = this.handleCloseInput.bind(this, false); this.confirmInput = this.handleCloseInput.bind(this, false);
@ -158,7 +159,14 @@ export class ApplicationDialogsProvider extends React.Component<
this.setState({ inputValue: e.target.value }); this.setState({ inputValue: e.target.value });
} }
submitInput(e: FormEvent<HTMLFormElement>) {
e.preventDefault();
this.handleCloseInput(false);
}
handleCloseInput(cancel: boolean) { handleCloseInput(cancel: boolean) {
if (!cancel && !this.isInputValid) return;
this.setState({ this.setState({
showInputDialog: false, showInputDialog: false,
}); });
@ -286,7 +294,7 @@ export class ApplicationDialogsProvider extends React.Component<
) : ( ) : (
<span></span> <span></span>
)} )}
<form onSubmit={this.submitInput}>
<TextField <TextField
label={this.state.inputOptions.label} label={this.state.inputOptions.label}
variant="outlined" variant="outlined"
@ -294,6 +302,7 @@ export class ApplicationDialogsProvider extends React.Component<
onChange={this.handleInputValueChanged} onChange={this.handleInputValueChanged}
type={this.state.inputOptions.type || "text"} type={this.state.inputOptions.type || "text"}
/> />
</form>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={this.cancelInput} color="default"> <Button onClick={this.cancelInput} color="default">