/** * Implicit form submission on Enter, for a control whose real editing surface is a native * `` living inside a shadow root. * * A native `` submits its form owner when the user presses Enter. The inputs these * components render have no form owner at all — they are in a shadow tree, and only the *host* * custom element participates in the light-DOM `
` — so the platform can never run implicit * submission for them. Without this, Enter in a text control inside a `` silently does * nothing, which reads as a broken form. * * The rules below are the platform's, not an approximation of them: * * - **Modifiers disqualify the keystroke.** `Ctrl`/`Cmd`/`Alt`/`Shift`+Enter is an application * shortcut (send-and-keep-open, insert-newline, open-in-new-tab), never implicit submission. * - **An IME composition Enter is not a submit.** Enter commits the highlighted candidate in * Japanese/Chinese/Korean input; submitting the form there throws away the word the user was * typing. `keyCode === 229` is the defense-in-depth fallback for engines that report * `isComposing` inconsistently on the `compositionend`-adjacent keydown. * - **A vetoed keydown stays vetoed.** A listener above this one (an autocomplete panel committing * a selection, a consumer's own shortcut) already claimed the keystroke. * - **The submitter is resolved, not skipped.** The form's *default button* is the first enabled * submit control in `form.elements`; a submission that ignores it loses `SubmitEvent.submitter`, * and with it the button's own `name`/`value` entry and its `formaction`/`formmethod`/ * `formnovalidate` overrides. A native submitter goes through `form.requestSubmit(submitter)`; * an `` is a form-associated custom element rather than a native submit button, so * `requestSubmit()` rejects it with a `TypeError` — it is activated through its own `click()`, * which runs the same submit path a real click would. * - **A submit-button-less form submits only from a single field.** The platform refuses implicit * submission when a form with no default button holds more than one field that blocks it. * * `requestSubmit()` (never `submit()`) is what runs interactive constraint validation, so an * invalid field blocks the submission exactly as a real submit button would. * * **Not wired everywhere on purpose.** Enter carries a different meaning in several controls, and * implicit submission must never shadow it: * - `` and `` — Enter inserts a newline, the whole point of a * multi-line surface. * - `` — its trigger is a `role="combobox"` button where Enter opens the listbox (and, * once open, commits the active option), per the ARIA combobox pattern its upstream counterpart * follows. * - `` — Enter selects the focused day in the calendar grid. * Callers also gate on their own `disabled`/`readonly` state before calling in, so a * non-interactive control stays inert. */ /** Options for {@linkcode submitOnEnter}. */ export interface SubmitOnEnterOptions{ /** * Runs immediately before the form is submitted, and only when a submission actually happens. * The hook a control uses to commit whatever it holds in transient, not-yet-published state * (typed-but-unparsed text, a pending `change`) so the submitted form value is what the user * sees rather than what they last committed. */ beforeSubmit?:()=>void;} /** Whether `element` is a native submitter accepted by `HTMLFormElement.requestSubmit()`. */ export declare function isNativeSubmitter(element:Element):element is HTMLButtonElement|HTMLInputElement; /** * Whether `event` is the platform's implicit-submission keystroke: a bare Enter, un-vetoed, and * outside an IME composition. Exported so a control that has its own work to do on that same * keystroke (committing typed text before the value is read) can apply one identical gate. */ export declare function isImplicitSubmission(event:KeyboardEvent):boolean; /** * The form's default button: the first enabled submit control in `form.elements` (tree order), * native or custom. `null` when the form has none. */ export declare function findImplicitSubmitter(form:HTMLFormElement):HTMLElement|null; /** * Performs the implicit form submission a native `` would perform for this keystroke. * * Returns `true` when a submission was actually requested, so a caller can branch on it (and so a * test can assert the decision rather than only its side effect). Does not call * `event.preventDefault()`: the keystroke has no default action to cancel here — the internal * input has no form owner — and cancelling it would suppress unrelated handlers downstream. * * @param host The form-associated custom element, i.e. the thing whose FACE `getForm()`/`form` * association owns submission — not the shadow-internal ``, which has no form owner. */ export declare function submitOnEnter(host:HTMLElement,event:KeyboardEvent,options?:SubmitOnEnterOptions):boolean;