Skip to content

fix: submit form on Enter in a single number input - #1345

Merged
snowystinger merged 1 commit into
testing-library:mainfrom
cschmertz:pr/implicit-submit-all-text-fields
Nov 18, 2026
Merged

snowystinger merged 1 commit into
testing-library:mainfrom
cschmertz:pr/implicit-submit-all-text-fields

Conversation

@cschmertz

Copy link
Copy Markdown
Contributor

What

Pressing Enter in a form's only number input doesn't submit the form (#1074):

document.body.innerHTML = `<form><input type="number"/></form>`
const form = document.querySelector('form')
form.addEventListener('submit', e => { e.preventDefault(); console.log('submit') })
await user.type(document.querySelector('input'), '42{Enter}')
// browser: "submit" is logged; user-event: nothing

Why

SubmitSingleInputOnEnter lists the input types where Enter submits a form that has no submit button, and number is missing from it, as pointed out on the issue. Since #1340 a number input already counts as a field that blocks implicit submission, so it could stop another field from submitting the form but couldn't submit it itself.

I checked the browsers with Playwright (Chromium 159, Firefox 159, WebKit 27.2). All three submit on Enter in a lone number input, and none do when the form has a second text field. I also checked date, time and datetime-local, which are in BlockImplicitSubmission but not in this list: none of the three browsers submit from those, so I left them out.

How

Added 'number' to SubmitSingleInputOnEnter, plus tests:

  • a lone number input submits on Enter, both at the keypress level and through user.keyboard('42{Enter}');
  • a number input next to another blocking field doesn't.

The two submit tests fail without the change. The full Jest suite passes, and test:toolbox gives the same results as main apart from the three new tests, which pass in every environment.

Checklist

  • Documentation: N/A
  • Tests
  • Ready to be merged

Closes #1074

Written with Claude Code; I reviewed the changes and ran the full suite locally.

Enter in the only field that blocks implicit submission submits the form, but number inputs were missing from the types that can trigger it. Chromium, Firefox and WebKit all submit in this case.

Closes testing-library#1074
@snowystinger
snowystinger merged commit b20f409 into testing-library:main Nov 18, 2026
3 of 4 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 14.6.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

number input does not trigger form submit on hitting enter

2 participants