holding down enter key submits form over and over
Bug report
Current Behavior
if you have a formik form on the same page as the destination for the rendered results, and you click enter, it allows you to submit the form. If you hold down the enter key, it submits over and over until you take your finger off the enter key. (I think this may be forms in general, and not solely formik forms?)
Expected behavior
the form should submit once, and not repeatedly while holding down the enter key
Reproducible example
any default formik setup
Suggested solution(s)
can the onSubmit trigger on key up of enter or trigger in some way that it won't continue to submit while holding down enter?
using the following code for now as a workaround:
const [submitOnEnterDisabled, setSubmitOnEnterDisabled] = useState(false);
const ENTER_KEY_CODE = 13
// SpecialLibrary props
onSubmit={(values) => {
if (!submitOnEnterDisabled){
submit(values);
}
}}
<Form
onKeyDown={(e) => {
if (e.keyCode === ENTER_KEY_CODE) {
if (!submitOnEnterDisabled){
submit(values);
}
setSubmitOnEnterDisabled(true);
}
}}
onKeyUp={(e) => {
if (e.keyCode === ENTER_KEY_CODE) {
setSubmitOnEnterDisabled(false);
}
}}
>
<button type="submit" onSubmit={submit}>Search</button>
Additional context
Your environment
| Software | Version(s) |
|---|---|
| Formik | 2.2.9 |
| React | 17.0.2 |
| TypeScript | n/a |
| Browser | chrome |
| npm/Yarn | npm |
| Operating System | windows |
This is because html vanilla forms check keyDown instead of checking for a full click / keyUp