feat: complete public Form migration and validation focus contract
This commit is contained in:
@@ -549,5 +549,9 @@
|
||||
".hv-avatar--lg",
|
||||
".hv-avatar--soft"
|
||||
]
|
||||
},
|
||||
"form": {
|
||||
"exports": ["Form", "FormRoot", "TextField", "Input", "Label", "FieldError", "Button"],
|
||||
"css": [".hv-textfield", ".hv-input", ".hv-field-error", ".hv-button"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
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,
|
||||
];
|
||||
Reference in New Issue
Block a user