Field Component Specification

A block of components that are all related to a single piece of data. Typically a label, an input, help text, and an error message.

Implementation

To comply with this spec, a Field type component must:

Properties

ALL properties are optional. The properties listed here are governed by this specification, but components are free to add any number of additional properties as necessary.

label

PropTypes.node

A label string or element to render. You may accept only strings if necessary.

errors

PropTypes.arrayOf(PropTypes.shape({
  message: PropTypes.string.isRequired,
  name: PropTypes.string.isRequired,
}))

The containing form will supply this if you specify a value for the name property. You may, but do not have to, add classes or adjust styles based on the errors passed in here.

isRequired

PropTypes.bool

If a field has the ability to show an indication that it is required, it must determine requiredness from the isRequired property. Note that this is unrelated to actual validation; it is for display purposes only.

Additional Properties

These properties are not strictly governed by this specification, but in order to make it easy to swap similar components, we recommend the following naming conventions:

Static Properties

defaultProps [OPTIONAL]

Setting the defaultProps static property is recommended but not required.

isFormField [REQUIRED]

Set this to true so that the containing form and other components know that your component implements the Field specification.

Example

ReactoForm Field