You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pressing enter in a text field does not submit form #4182
changed the title [-]Form submission not working for button nor text field[/-][+]Form submission not working for button nor text field on Firefox[/+]on Sep 17, 2023
There is the presence of an input or button with type=submit
As the Material buttons do not inherit from the HTMLButtonElement it's likely that browsers do not apply the above rules to them.
I see, I misunderstand you. A form with a single focused input can be submitted with enter even when there's no submit button. (Didn't know that!) Adding more inputs and the form won't submit anymore.
Will alert
<form onsubmit="event.preventDefault(); alert('submitted')">
<label>Input one <input type="text" name="input1" /></label>
</form>
changed the title [-]Form submission not working for button nor text field on Firefox[/-][+]Form submission not working for button nor text field[/+]on Sep 18, 2023
further investigation here. Seems that the form does submit. It seems in FF the form.submitter value is not being set correctly. Since this issue is solved closing. For submitter issues please see #4949
changed the title [-]Form submission not working for button nor text field[/-][+]Pressing enter in a text field does not submit form[/+]on Sep 18, 2023
Updated the title. Text fields do add their data to submitting forms, but pressing the enter key in a text field will not automatically submit its form right now. You'll need to add keydown listeners and handle that manually.
Also just in case it's relevant, a button in a trailing-icon slot should also submit the form. Currently pressing Enter on any element but text fields does submit the form. Clicking a button (including the one on the trailing-icon slot), pressing Enter on standard <input> and <button> all submit the form: https://jsfiddle.net/datvm/3h0k89do/2/
a button in a trailing-icon slot should also submit the form
I don't think I agree from an a11y perspective. Icon buttons contained within a text field should have functionality tied to the text field itself, such as a clear button or a password visibility toggle.
It may be unexpected to have a form submit when using the enter key to trigger the icon button.
Activity
asyncliz commentedon May 26, 2023
The button submission will be fixed in an upcoming PR.
Do native input text field submit forms on enter keypress? What happens if there are multiple?
rarous commentedon Aug 20, 2023
@asyncliz Yes, native input submits form when you press enter. Event if there are multiple. Please, keep native behaviour.
Totati commentedon Sep 5, 2023
I've created a demo for submit and reset events. Submit buttons now work.
juanmarin-co commentedon Sep 7, 2023
@Totati I've tested your demo in Firefox and Chrome, it does work on Chrome but does not work on Firefox
Totati commentedon Sep 8, 2023
You are right.
e111077 commentedon Sep 17, 2023
Updating issue title since it works on chrome
[-]Form submission not working for button nor text field[/-][+]Form submission not working for button nor text field on Firefox[/+]austinw-fineart commentedon Sep 18, 2023
I believe what you're experiencing is a browser quirk when handling forms. Specifically, the Enter key will only submit when either:
As the Material buttons do not inherit from the HTMLButtonElement it's likely that browsers do not apply the above rules to them.
Totati commentedon Sep 18, 2023
This is not true -> https://stackblitz.com/edit/js-raarmc Both in Chromium and Firefox the form gets submitted
Yes, this is true, and they try to come around this by creating a submit button
austinw-fineart commentedon Sep 18, 2023
You added a button (type is submit by default) 😛
Totati commentedon Sep 18, 2023
I see, I misunderstand you. A form with a single focused input can be submitted with enter even when there's no submit button. (Didn't know that!) Adding more inputs and the form won't submit anymore.
Will alert
Won't alert
Will alert
I have updated my demo for the reset and submit event.
[-]Form submission not working for button nor text field on Firefox[/-][+]Form submission not working for button nor text field[/+]e111077 commentedon Sep 18, 2023
further investigation here. Seems that the form does submit. It seems in FF the form.submitter value is not being set correctly. Since this issue is solved closing. For submitter issues please see #4949
Totati commentedon Sep 18, 2023
@e111077 The form does not submit for text-field in Chrome nor in FF. 🤷♂️ Could you provide an example where it works please? I'm interested what did I wrong in my reproduction.
e111077 commentedon Sep 18, 2023
sorry for the hasty close
[-]Form submission not working for button nor text field[/-][+]Pressing enter in a text field does not submit form[/+]asyncliz commentedon Sep 18, 2023
Updated the title. Text fields do add their data to submitting forms, but pressing the enter key in a text field will not automatically submit its form right now. You'll need to add
keydownlisteners and handle that manually.datvm commentedon Oct 4, 2023
Also just in case it's relevant, a button in a
trailing-iconslot should also submit the form. Currently pressing Enter on any element but text fields does submit the form. Clicking a button (including the one on thetrailing-iconslot), pressing Enter on standard<input>and<button>all submit the form: https://jsfiddle.net/datvm/3h0k89do/2/So the only problem now is to submit the form on pressing Enter on Material Text field.
asyncliz commentedon Oct 4, 2023
I don't think I agree from an a11y perspective. Icon buttons contained within a text field should have functionality tied to the text field itself, such as a clear button or a password visibility toggle.
It may be unexpected to have a form submit when using the enter key to trigger the icon button.
datvm commentedon Oct 4, 2023
@asyncliz that's a good point, thanks. I will fix my app by switching it to a separate button.
Still pressing Enter in the textfield should trigger the form submit. Currently I have to manually handle the textfield's
keydownevent.mai1202 commentedon Dec 20, 2023
Have the bug fixed? It still cannot work on the latest Chrome.
asyncliz commentedon Dec 20, 2023
Not yet, the issue is still open
therealabdi2 commentedon Jun 14, 2025
Any update or wrokaround for this?
asyncliz commentedon Jun 15, 2025
The workaround is to add a keypress listener and programmatically submit the form when the enter key is pressed.