Field
The Field component wraps a label, an input, and optional helper or error
text into a single, themed unit. It replaces the old Block component from
9.x and adds first-class support for hint and error states.
Quick Start
To start using the Field component, import it from reablocks.
Examples
Label
Hint
A hint displays guidance text below the input:
Error
The error prop accepts a boolean or a ReactNode. When set, it replaces
the hint and is rendered with role="alert" so it’s announced by screen
readers.
When both hint and error are present, error takes precedence:
<Field
label="Email"
error={errors.email?.message ?? false}
>
<Input />
</Field>Horizontal layout
Blocks
This component is used in the following Blocks:
Theme
This component uses the following default theme:
- root{}(11 keys)
- Show all
interface FieldTheme {
base: string;
disableMargin: string;
label: string;
hint: string;
error: string;
errorState: string;
centerAlign: string;
endAlign: string;
horizontal: {
base: string;
label: string;
content: string;
};
vertical: {
base: string;
label: string;
};
}Learn more about how to customize in the Theme documentation.
API
Migrating from Block
Block was renamed to Field in 10.0.0.
// Before
import { Block } from 'reablocks';
<Block label="Email"><Input /></Block>
// After
import { Field } from 'reablocks';
<Field label="Email"><Input /></Field>| Before | After |
|---|---|
Block | Field |
BlockProps | FieldProps |
BlockTheme | FieldTheme |
blockTheme | fieldTheme |
components.block | components.field |
See the full guide in Migration.