I am implementing filter data feature. Following code is on-fly search feature. Is there any way to implement show result after pressing Enter key? Means only pressing Enter key user can see the result
import React, { Fragment } from "react";
import { TextField, makeStyles } from "@material-ui/core";
const useStyle = makeStyles((theme) => ({
inputRoot: {
backgroundColor: "white",
borderRadius: 10,
},
inputInput: {
padding: theme.spacing(1, 1, 1, 2),
transition: theme.transitions.create("width"),
width: "100%",
[theme.breakpoints.up("md")]: {
width: 80,
},
},
}));
const SearchBox = ({ onSubmit }) => {
const classes = useStyle();
const [formData, setFormData] = React.useState({
keyword: "",
});
const { keyword } = formData;
const handleChange = (keyword) => (e) => {
setFormData({ ...formData, [keyword]: e.target.value });
};
onSubmit(keyword);
return (
<Fragment>
<TextField
value={keyword}
placeholder="Search…"
onChange={handleChange("keyword")}
className={classes.inputRoot}
margin="normal"
size="small"
autoFocus={true}
variant="outlined"
/>
</Fragment>
);
};
export default SearchBox;