Skip to content

Instantly share code, notes, and snippets.

@Fanoflix
Last active October 14, 2024 08:10
Show Gist options
  • Save Fanoflix/e62011f378cdd84cd790b322fc114688 to your computer and use it in GitHub Desktop.
Save Fanoflix/e62011f378cdd84cd790b322fc114688 to your computer and use it in GitHub Desktop.
Ctrl + Enter to submit Form (Typescript)
document.body.addEventListener("keydown", (e: KeyboardEvent) => {
if (!(e.key === "Enter" && (e.metaKey || e.ctrlKey))) return
if ('form' in e.target) {
const formElement = e.target.form as HTMLFormElement;
formElement?.submit(); // or formElement?.requestSubmit() depending on your usecase
}
})
@Fanoflix
Copy link
Author

Fanoflix commented Oct 13, 2024

@oleksandr-danylchenko Thanks! Updated the gist.

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