Skip to content

fix: match browser spec for form implicit submission - #1340

Merged
snowystinger merged 3 commits into
testing-library:mainfrom
yxshee:fix/implicit-submit-blocking-fields
Nov 12, 2026
Merged

snowystinger merged 3 commits into
testing-library:mainfrom
yxshee:fix/implicit-submit-blocking-fields

Conversation

@yxshee

@yxshee yxshee commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

What

Pressing Enter in the only text field of a form without a submit button does not submit the form when the form also contains radio buttons, checkboxes or hidden inputs.

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

Why

The single-field check counts every <input> in the form (form.querySelectorAll('input').length === 1). The HTML spec only counts fields that block implicit submission: inputs of type text, search, tel, url, email, password, date, month, week, time, datetime-local and number. Radio, checkbox, hidden, range and similar inputs do not stop implicit submission. I checked this in Chrome 152: Enter in the text field submits <form><input type=radio><input><input type=checkbox><input type=hidden></form>, but not when a <input type=number> is added.

As asked in #1255, this is defined in the spec.

How

Count only the inputs whose type is in the spec's list of blocking fields.

Two cases were added to the submit form on [Enter] table in tests/event/behavior/keypress.ts. On main the new radio/checkbox/hidden case fails with Expected: true, Received: false on the submit assertion. With the change, the full jest suite (522 tests), lint and typecheck pass, and the toolbox run passes the keypress tests in both Node environments.

Fixes #1255

Checklist

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

@snowystinger snowystinger changed the title fix: only count fields that block implicit submission on [Enter] fix: match browser spec for form implicit submission Nov 12, 2026

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few more tests and found some discrepancies. Given that the browsers don't all behave the same, I'm find adhering to the spec and hopefully the browsers will eventually match.

},
)

test.each([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some discrepancies with these

Chrome allows submission with additional date, month, week, time, or datetime-local inputs

Safari 27.0.1 and Firefox 158 both allow submission despite an additional date, time, or datetime-local input
The difference is month and week, Safari and Firefox treat these types as ordinary text inputs, so they block submission

@snowystinger
snowystinger merged commit 98b7f26 into testing-library:main Nov 12, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 14.6.10 🎉

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.

userEvent.keyboard('{Enter}') does not trigger form submission in forms with radio group elements

2 participants