From a2566e186a500bb83d2fedf57ee2c08e6a626f4e Mon Sep 17 00:00:00 2001 From: Zacky Ma Date: Fri, 22 May 2026 12:01:38 -0700 Subject: [PATCH 1/3] prevent text-input from submitting twice when Enter is pressed --- .../src/text-input/text-input.base.ts | 13 --------- .../src/text-input/text-input.spec.ts | 28 +++++++++++++++++++ .../src/text-input/text-input.template.ts | 1 - 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/web-components/src/text-input/text-input.base.ts b/packages/web-components/src/text-input/text-input.base.ts index b54dcf861c5f2..1326aca0153cd 100644 --- a/packages/web-components/src/text-input/text-input.base.ts +++ b/packages/web-components/src/text-input/text-input.base.ts @@ -418,19 +418,6 @@ export class BaseTextInput extends FASTElement { return this.elementInternals.form; } - /** - * Handles the internal control's `keypress` event. - * - * @internal - */ - public beforeinputHandler(e: InputEvent): boolean | void { - if (e.inputType === 'insertLineBreak') { - this.implicitSubmit(); - } - - return true; - } - /** * Change event handler for inner control. * diff --git a/packages/web-components/src/text-input/text-input.spec.ts b/packages/web-components/src/text-input/text-input.spec.ts index f88e019b164bd..ff957f0ecb518 100644 --- a/packages/web-components/src/text-input/text-input.spec.ts +++ b/packages/web-components/src/text-input/text-input.spec.ts @@ -699,6 +699,34 @@ test.describe('TextInput', () => { expect(page.url()).toMatch(/foo/); }); + test('should only submit form once when Enter is pressed', async ({ fastPage }) => { + const { element, page } = fastPage; + const control = element.locator('input'); + const form = page.locator('form'); + + await fastPage.setTemplate(/* html */ ` +
+ <${tagName} name="testinput"> +
+ `); + + await form.evaluate(node => { + node.addEventListener('submit', evt => { + if (!node.dataset.count) { + node.dataset.count = '0'; + } + const count = Number(node.dataset.count) + 1; + node.dataset.count = String(count); + evt.preventDefault(); + }); + }); + + await control.focus(); + await page.keyboard.press('Enter'); + + await expect(form).toHaveAttribute('data-count', '1'); + }); + test('should allow comma-separated values when the `multiple` attribute is set and the `type` is "email"', async ({ fastPage, page, diff --git a/packages/web-components/src/text-input/text-input.template.ts b/packages/web-components/src/text-input/text-input.template.ts index 0a46b61867df6..d10a5385f09a7 100644 --- a/packages/web-components/src/text-input/text-input.template.ts +++ b/packages/web-components/src/text-input/text-input.template.ts @@ -11,7 +11,6 @@ import type { TextInputOptions } from './text-input.options.js'; export function textInputTemplate(options: TextInputOptions = {}): ElementViewTemplate { return html`