Hooks
useFieldControl
Read the surrounding Field context (control id, name, disabled, invalid, and ARIA associations) inside custom form controls.
Import
import {
Field,
useFieldControl,
} from "@/components/ui/hacline/components/field";Usage
Call useFieldControl() inside a custom input placed within <Field> to automatically inherit the field's id, name, disabled, invalid, and aria-describedby bindings. Returns null when rendered outside a <Field>.
import {
Field,
FieldDescription,
FieldLabel,
} from "@/components/ui/hacline/components/field";
import { useFieldControl } from "@/components/ui/hacline/components/field";
const CustomTagInput = () => {
const field = useFieldControl();
return (
<input
aria-invalid={field?.invalid || undefined}
disabled={field?.disabled}
id={field?.id}
name={field?.name}
placeholder="Add tags..."
type="text"
/>
);
};
export const Example = () => (
<Field name="tags">
<FieldLabel>Tags</FieldLabel>
<CustomTagInput />
<FieldDescription>Separate multiple tags with commas.</FieldDescription>
</Field>
);