feat: add Checkbox and Radio field families
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user