components / field

field.

label, control, hint and error as one accessible unit. the render-prop form hands the control its id, aria-describedby, aria-invalid and required already computed, so a field is announced correctly without matching ids by hand. an error replaces the hint rather than stacking under it.

installation
bunx @justin06lee/chrome@latest add field
props
nametypedefaultdescription
label *ReactNode-label text.
children *ReactNode | ((props: FieldControlProps) => ReactNode)-the control. pass a function to receive { id, aria-describedby, aria-invalid, required } and spread it onto the input.
htmlForstring-explicit control id; one is generated when omitted.
hintReactNode-muted line under the control. hidden while an error is showing.
errorReactNode-error text. its presence is what marks the field invalid.
requiredbooleanfalseadds a marker to the label and sets required on the control.
optionalbooleanfalserenders a muted "optional" tag instead. ignored when required.
labelHiddenbooleanfalsekeeps the label for screen readers only.
actionReactNode-trailing slot on the label row — a counter, a "forgot?" link.
classNamestring-