Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Comment thread
marchbox marked this conversation as resolved.
"type": "prerelease",
"comment": "prevent text input from submitting its associated form twice when Enter is pressed",
"packageName": "@fluentui/web-components",
"email": "machi@microsoft.com",
"dependentChangeType": "patch"
}
2 changes: 0 additions & 2 deletions packages/web-components/docs/web-components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,6 @@ export class BaseTextInput extends FASTElement {
autocomplete?: string;
autofocus: boolean;
// @internal
beforeinputHandler(e: InputEvent): boolean | void;
// @internal
changeHandler(e: InputEvent): boolean | void;
checkValidity(): boolean;
clickHandler(e: MouseEvent): boolean | void;
Expand Down
13 changes: 0 additions & 13 deletions packages/web-components/src/text-input/text-input.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
28 changes: 28 additions & 0 deletions packages/web-components/src/text-input/text-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ `
<form>
<${tagName} name="testinput"></${tagName}>
</form>
`);

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { TextInputOptions } from './text-input.options.js';
export function textInputTemplate<T extends TextInput>(options: TextInputOptions = {}): ElementViewTemplate<T> {
return html<T>`
<template
@beforeinput="${(x, c) => x.beforeinputHandler(c.event as InputEvent)}"
@focusin="${(x, c) => x.focusinHandler(c.event as FocusEvent)}"
@keydown="${(x, c) => x.keydownHandler(c.event as KeyboardEvent)}"
>
Expand Down
Loading