Skip to content

FRM-015 Let Enter in a single-line field send the form, as its main button does

Level
Rule
Verdict
Unanimous (3 of 3)
Area
Forms
Status
proposed, version 1.0.0

Rule

In a form, pressing Enter in a single-line field, such as a text, email, number or search input, sends the form, the same as pressing its main button.

Examples

Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.

Do: A real form with a submit button

Invite a teammate

Invites sent: 0

Click in Email address and press Enter. The invite is sent, exactly as a click on Send invite does, and the tally goes up. The field and the button sit in one <form> and the button is type="submit".

Don't: A div and a click handler

Invite a teammate

Invites sent: 0

Click in Email address and press Enter. Nothing happens and the tally stays at 0. Click Send invite and it goes. There is no <form>, so the browser has nothing to send.

Do: Helper buttons are plain buttons

Sign in

Sign-ins: 0

Click in Password and press Enter. You are signed in. Press Show password with Enter or Space and the password shows, without signing in. The helper has type="button", so Enter never presses it.

Don't: A helper without a type, before the main button

Sign in

Sign-ins: 0

Click in Password and press Enter. The password is shown and nobody is signed in. The browser presses the first submit button in the code, and Show password has no type, so Enter lands on it. Its click handler calls preventDefault() so that a click on the eye does not send the form, and that also cancels the send Enter started. Without that call, Enter would show the password and send the form too. Click Sign in to see it work.

Why

People who type expect to finish with the key under their hand. When Enter in the last field does nothing, they have to reach for the pointer or tab past every other control to find the button, and someone who relies on the keyboard pays that every time. When Enter does something other than the main button, such as clearing a field or adding a row, the press they meant as "done" quietly does the wrong thing. On the web the browser already gives this for free, but only when the form is built as a real form with a real submit button, and that is easy to break in a React app without noticing.

No WCAG criterion asks for Enter to send a form, so this rule rests on the judges. The law points the same way. WCAG 2.2, 3.2.2 On Input is about values that change the context by themselves; pressing Enter to send is the person asking on purpose, the same as pressing the button, so it sits outside what that criterion forbids and on the other side of FRM-012a. 2.1.1 Keyboard asks that the keyboard can do the job; Enter in a field is one route to sending, though a submit button that Tab reaches is enough for that criterion on its own.

Do

  • On Apply for an allotment plot, the fields Full name, Email address and Preferred site sit in one <form onSubmit={form.handleSubmit(onSubmit)}> with <Button type="submit">Send application</Button> at the end. Enter in any of the text fields sends the application, exactly as a click on Send application does.
  • A one-field form works the same way. In a team settings page, Email address sits above a Send invite button, both inside a <form>. The person types an address, presses Enter, and the invite goes out. A tag field labelled New tag with an Add tag button does the same.
  • In a Dialog titled Rename board, put the <form> around the field and the DialogFooter, so the Save name submit button is inside it. If the layout keeps the footer outside, give the form an id and the button form with that id.
  • On a step of a multi-step form, Enter does what Continue does: it sends that step.
  • Our own advice: make the main button the only submit button in the form, or the first one in the code, and give every helper button type="button": a Show password eye, a Clear icon, Add another address, a stepper's plus and minus, and Cancel. The stock shadcn Button renders a plain button with no type, which inside a form is a submit button unless told otherwise, and the browser presses the first one in the code. Justified's Button defaults to type="button" instead, so with it the main button needs type="submit" written out. A Save draft that sends the form with formAction may stay a submit button if it comes after the main one.
  • On Edit contact, Delete contact sits in the same row as Save contact. Give it type="button". Left without a type and placed first in the code, it is what Enter presses, the worst form of this break.
  • When Enter sends a form with problems, handle it exactly like a click on the main button: focus goes to the first problem or to a summary, as FRM-011 says, and the errors show at their fields, as FRM-002a says.
  • The guard against a second send sits on the form's submit, not only on the button's click, as the guideline STA-005b advises. Enter pressed twice then sends once.
  • react-hook-form and server actions both work with the native form. Nothing more is needed than the <form> and type="submit".
  • Our own advice: let the browser do it. If a custom Enter handler cannot be avoided, call form.requestSubmit(), which runs validation and the submit event, never form.submit(), which skips both. Ignore Enter while an input method is still composing text (e.nativeEvent.isComposing), so people typing Japanese, Chinese or Korean do not send half a word.

Don't

  • Lay out Email address and Send invite in a div with onClick={sendInvite} on the button and no <form>, so Enter in the field does nothing.
  • Give the main button type="button" and send from its onClick. With two fields Enter then does nothing; with one field the browser still sends the form, but around the click handler and whatever it does.
  • Stop "early sends" with an onKeyDown that calls preventDefault() on Enter. If people send too soon, that is a question for validation (FRM-002b, FRM-011), not a blocked key.
  • Leave the Show password eye without a type, before Sign in in the code, so Enter in the password field shows the password instead of signing in.
  • Listen for Enter on document and send whichever form is on screen. That is not the browser's behaviour and fires from places this rule does not cover.

Exceptions

  • Multi-line fields. In a Textarea, Enter adds a new line, as the browser does by default. This rule does not change that. A chat composer that sends on Enter and adds a line with Shift+Enter is a product choice outside this rule; our own advice there is to say on screen how to add a line and to ignore Enter while an input method is composing.
  • Controls where Enter has its own job. In an open Select, Combobox or Command list, a date picker grid or a list of suggestions, Enter picks the item and does not send the form; FRM-012b and FRM-013 already say a choice only records it. A button with focus runs itself, not the main button.
  • Destructive confirmations. This rule does not apply where the person confirms a destructive action. In a dialog, Enter in a field, such as one asking for the name of what will be deleted, must not run the action, as DLG-004 says. Our own choice: the same holds on a page, such as Delete account behind a field that asks for the account name.
  • Two equal choices. When a form has two submit buttons and neither is the main one, this rule does not decide which one Enter presses; the browser takes the first in the code. Our own advice: put the safer one first. Enter still never presses a helper button such as Show password.
  • An unavailable main button. A submit button that is switched off also stops Enter. The guideline ACT-004 advises keeping it on in long forms. Where ACT-004 leaves a short form out of scope and the team switches the button off, Enter doing nothing is expected, and the note before the button says why, as ACT-005 asks.
  • Fields outside a form. A filter box that narrows a list as people type, or an inline rename in a table cell, is not a form. What Enter does there is not decided by this rule.
  • Neighbouring rules. The keyboard in general is KBD-001; this rule is a narrower case and KBD-001 does not require it on its own. Which button gets the emphasised style is ACT-002a.

Verdict

Unanimous (3 of 3). Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work

Stances on FRM-015
SourceRoleStancePage
WCAG 2.2LawSupports3.2.2 On Input
WCAG 2.2LawSupports2.1.1 Keyboard
Material DesignJudge SupportsAccessibility designing: flow
Apple Human Interface GuidelinesJudge SupportsButtons
Alerts
Virtual keyboards (ios, ipados, tvos, visionos, watchos; no web guidance)
Carbon Design SystemJudge SupportsButton: usage
Search: accessibility
Text input: accessibility
GOV.UK Design SystemExpert witness No position
Nielsen Norman GroupExpert witness No position

Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.

History

  • Version 1.0.0, : First version.

Last checked against the other rules for conflicts on .

More in Forms: 15 rules and 12 guidelines · All rules