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.

PropType / variantsPurposeDefault
childrenReactNodeField parts: label, control, description and error text.—
errorbooleanShows the error state.false
htmlForstringAssociates the label with the input id.—
disabledbooleanDisables interaction.false
classNamestringClass of the root element.—

Native HTML attributes are accepted where the component renders the corresponding element. className props only affect styling.