feat: add Checkbox and Radio field families

This commit is contained in:
maoyingjie
2026-10-22 09:15:27 +08:00
parent a4fb3c550a
commit bcadbeaf8c
75 changed files with 5293 additions and 22 deletions
+3 -2
View File
@@ -3,15 +3,16 @@ import type { ComputedRef, InjectionKey, Ref } from "vue";
export type ValidationBehavior = "native" | "aria";
export type ValidationErrors = Record<string, string | string[]>;
export type ValidateResult = string | string[] | true | null | undefined;
export type FieldPart = "description" | "error";
export type FieldPart = "description" | "error" | "label";
export interface FieldContext {
controlId: ComputedRef<string>;
kind: "text" | "toggle";
kind: "text" | "toggle" | "group";
disabled: ComputedRef<boolean>;
readOnly: ComputedRef<boolean>;
required: ComputedRef<boolean>;
invalid: ComputedRef<boolean>;
errors: ComputedRef<string[]>;
labelIds?: Ref<string[]>;
descriptionIds: Ref<string[]>;
errorIds: Ref<string[]>;
}
@@ -8,7 +8,12 @@ export function useFieldPart(part: FieldPart, attrs: Record<string, unknown>) {
const id = computed(() =>
typeof attrs.id === "string" ? attrs.id : generated,
);
const ids = part === "description" ? field?.descriptionIds : field?.errorIds;
const ids =
part === "label"
? field?.labelIds
: part === "description"
? field?.descriptionIds
: field?.errorIds;
const stop = watch(
id,
(current, _, cleanup) => {