fix: complete field and OTP public contracts (HD-07)

This commit is contained in:
maoyingjie
2026-10-29 09:30:58 +08:00
parent 27cc62e36f
commit 2d7e3d4e1e
26 changed files with 1067 additions and 100 deletions
+15
View File
@@ -871,5 +871,20 @@
".hv-date-picker__trigger",
".hv-date-range-picker__trigger"
]
},
"field-otp": {
"exports": [
"TextField",
"SearchField",
"FieldError",
"InputOTP",
"InputOTPSlot"
],
"css": [
".hv-textfield",
".hv-search-field",
".hv-field-error",
".hv-input-otp__input"
]
}
}
+51
View File
@@ -0,0 +1,51 @@
import { h } from "vue";
import {
TextField,
SearchField,
type TextFieldProps,
type SearchFieldProps,
type TextFieldRenderProps,
type SearchFieldRenderProps,
type InputOTPProps,
} from "@heroui-vue/components";
const text: TextFieldProps = { autoFocus: true, validationErrors: ["server"] };
const search: SearchFieldProps = { validationErrors: "local", autoFocus: true };
const otp: InputOTPProps = {
maxLength: 4,
autoFocus: true,
textAlign: "right",
pasteTransformer: (text) => text.replaceAll("-", ""),
};
const textSlot: NonNullable<
InstanceType<typeof TextField>["$slots"]["default"]
> = (state: TextFieldRenderProps) => [
h(
"span",
`${state.value}/${state.isFocusWithin}/${state.validationDetails.valid}`,
),
];
const searchSlot: NonNullable<
InstanceType<typeof SearchField>["$slots"]["default"]
> = (state: SearchFieldRenderProps) => [
h("span", `${state.value}/${state.isEmpty}/${state.isFocusVisible}`),
];
// @ts-expect-error errors are local text/arrays, not Form name maps
const badField: TextFieldProps = { validationErrors: { email: "wrong" } };
// @ts-expect-error text alignment is a closed union
const badAlignment: InputOTPProps = { maxLength: 4, textAlign: "bottom" };
// @ts-expect-error the paste transformer returns a string
const badPaste: InputOTPProps = { maxLength: 4, pasteTransformer: () => 42 };
const badDetails: InputOTPProps = {
maxLength: 4,
// @ts-expect-error all native validity flags are required
validationDetails: { valid: false },
};
void text;
void search;
void otp;
void textSlot;
void searchSlot;
void badField;
void badAlignment;
void badPaste;
void badDetails;