UNPKG

@conform-to/dom

Version:

A set of opinionated helpers built on top of the Constraint Validation API

65 lines 3.12 kB
/** * Element that user can interact with, * includes `<input>`, `<select>` and `<textarea>`. */ export type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement; /** * Form Control element. It can either be a submit button or a submit input. */ export type Submitter = HTMLInputElement | HTMLButtonElement; export declare function isInputElement(element: Element): element is HTMLInputElement; export declare function isSelectElement(element: Element): element is HTMLSelectElement; export declare function isTextAreaElement(element: Element): element is HTMLTextAreaElement; /** * A type guard to check if the provided element is a field element, which * is a form control excluding submit, button and reset type. */ export declare function isFieldElement(element: unknown): element is FieldElement; /** * Resolves the action from the submit event * with respect to the submitter `formaction` attribute. */ export declare function getFormAction(event: SubmitEvent): string; /** * Resolves the encoding type from the submit event * with respect to the submitter `formenctype` attribute. */ export declare function getFormEncType(event: SubmitEvent): 'application/x-www-form-urlencoded' | 'multipart/form-data'; /** * Resolves the method from the submit event * with respect to the submitter `formmethod` attribute. */ export declare function getFormMethod(event: SubmitEvent): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** * Trigger a form submit event with an optional submitter. * If the submitter is not mounted, it will be appended to the form and removed after submission. */ export declare function requestSubmit(form: HTMLFormElement | null | undefined, submitter: Submitter | null): void; export declare function createFileList(value: File | File[]): FileList; type InputCallback = (event: { type: 'input' | 'reset' | 'mutation'; target: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement; }) => void; type FormCallback = (event: { type: 'submit' | 'input' | 'reset' | 'mutation'; target: HTMLFormElement; submitter?: HTMLInputElement | HTMLButtonElement | null; }) => void; export declare function createGlobalFormsObserver(): { onFieldUpdate(callback: InputCallback): () => void; onFormUpdate(callback: FormCallback): () => void; dispose(): void; }; export declare function change(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, value: string | string[] | File | File[] | FileList | null): void; export declare function focus(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): void; export declare function blur(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): void; export declare function normalizeFieldValue(value: unknown): [string[] | null, FileList | null]; /** * Updates the DOM element with the provided value and defaultValue. */ export declare function updateField(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, options: { value?: unknown; defaultValue?: unknown; }): void; export {}; //# sourceMappingURL=dom.d.ts.map