Field
A wrapper for a label, control, description and error state.
Compose Field.Label, Field.Control, Field.Description, and Field.Error. error marks invalid input. Field.Description and Field.Error texts are linked to the control via aria-describedby; the control's own error is kept.
Live example
Example controls
Usage
'use client';
import { Field, Input } from '@prosazhin/pbcomponents';
import { useState } from 'react';
function Example() {
const [value, setValue] = useState('');
return (
<Field error={!value}>
<Field.Label>Label</Field.Label>
<Field.Control>
<Input>
<Input.Control
value={value}
onChange={setValue}
placeholder='Placeholder'
/>
</Input>
</Field.Control>
<Field.Description>Description</Field.Description>
{!value && <Field.Error>Fill in the field</Field.Error>}
</Field>
);
}Component API
Compound parts: Field.Label, Field.Control, Field.Description, Field.Error.
| Prop | Type / variants | Purpose | Default |
|---|---|---|---|
children | ReactNode | Field parts: label, control, description and error text. | — |
error | boolean | Shows the error state. | false |
htmlFor | string | Associates the label with the input id. | — |
disabled | boolean | Disables interaction. | false |
className | string | Class of the root element. | — |
Native HTML attributes are accepted where the component renders the corresponding element. className props only affect styling.