From 06b262d1e06545470d32353cac722168e3672a99 Mon Sep 17 00:00:00 2001 From: ido Date: Mon, 20 May 2024 21:00:54 +0300 Subject: [PATCH] fix(submit): textarea shortcut --- packages/forms/src/components/WebForms.astro | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/forms/src/components/WebForms.astro b/packages/forms/src/components/WebForms.astro index 1f4afb4..39341bc 100644 --- a/packages/forms/src/components/WebForms.astro +++ b/packages/forms/src/components/WebForms.astro @@ -38,9 +38,12 @@ const clientScript = Astro.locals.forms.scriptToRun; } window.__enterToSubmit = function (event) { - if (event.code === 'Enter') { + const target = event.target as HTMLElement; + const isMultiLine = target instanceof HTMLTextAreaElement; + + if ((isMultiLine && event.ctrlKey || !isMultiLine) && event.code === 'Enter') { event.preventDefault(); - document.getElementById((event.target as HTMLElement).getAttribute('data-submit')!)?.click(); + document.getElementById(target.getAttribute('data-submit')!)?.click(); } };