Files
heroui-vue/tests/package/form-contract.ts
T

49 lines
1.6 KiB
TypeScript

import { h } from "vue";
import {
Form,
FormRoot,
type FormProps,
type FormRootProps,
type FormSlots,
type FormExpose,
} from "@heroui-vue/components";
const props: FormProps = {
validationBehavior: "native",
validationErrors: { email: ["Invalid"] },
action: "/submit",
method: "post",
enctype: "multipart/form-data",
target: "_self",
noValidate: true,
"aria-label": "Account",
class: ["flex", { compact: true }],
onSubmit: (event: SubmitEvent) => event.preventDefault(),
onReset: (event: Event) => event.preventDefault(),
onInvalid: (event: Event) => event.preventDefault(),
};
const rootProps: FormRootProps = props;
const slots: FormSlots = { default: () => h("input", { name: "email" }) };
h(Form, rootProps, { default: slots.default });
h(FormRoot, { validationBehavior: "aria" });
declare const form: FormExpose;
const valid: boolean = form.checkValidity();
const reported: boolean = form.reportValidity();
form.reset();
form.element?.requestSubmit();
// @ts-expect-error validation mode is constrained
const invalidMode: FormProps = { validationBehavior: "automatic" };
// @ts-expect-error field errors accept strings or string arrays
const invalidErrors: FormProps = { validationErrors: { email: 42 } };
// @ts-expect-error no React render function API
const invalidRender: FormProps = { render: () => h("form") };
// @ts-expect-error submit receives native SubmitEvent, not a field value
const invalidSubmit: FormProps = { onSubmit: (value: string) => value };
void [
valid,
reported,
invalidMode,
invalidErrors,
invalidRender,
invalidSubmit,
];