Balance Logo
Balance
Reckon Design System
Open playroom

Field

The field package exposes the elements around form inputs, and an API to compose them.
Install
pnpm add @balance-web/field
Import usage
import {
Field,
FieldDescription,
FieldLabel,
FieldMessage,
HelpIndicator,
useFieldContext,
useRemainingCharactersGuidance
} from '@balance-web/field';
  • Code
  • API

Alternatives

  • Fieldset — For grouping related form controls.

Field

Using context, the field component connects the label, description, and message to the input element.

Edit in Playroom

label

Each text field must be accompanied by a label. Effective form labeling helps users understand what information to enter into a text input.

Using placeholder text in lieu of a label is sometimes employed as a space-saving method. However, this is not recommended because it hides context and presents accessibility issues.

labelVisible

There may be occasions where the label is apparent through context to sighted users, so you wish to omit it from the view. We still need a label attached to the input for assistive technology, in these cases you can provide the labelVisible property.

description

Description text contains pertinent information that assists the user in completing a field. Description text is always visible and appears underneath the label. Use sentence-style capitalisation, and in most cases, write the text as full sentences with punctuation.

You can pass a ReactElement as description. This should only be used when you need to put a link or some other interactive element in the description.

You don't need to concern yourself styling the text, it will be handled by the component. Just render your normal text inside a Fragment and use a TextLink component to render the link.

Note: Try not to make the description a complex component, it's supposed to support the user not overwhelm them.

helpText

Help text is hidden by default, and revealed in a tooltip invoked by an icon beside the label. Reserve help text for content only relevant during the first interaction a user has with the field. Use sentence-style capitalisation, and in most cases, write the text as full sentences with punctuation.

In most cases description is preferred.

invalidMessage

Offer an invalid message to inform the user how their input violates the requirements of the field.

reserveMessageSpace

Reserve the vertical space that will be taken by an invalid message. You would use this to stop subsequent elements from being pushed down when an invalid message is displayed.

guidance

Field guidance is an extra information about the field. For example, it can be used to show remaining characters of the input field with maxLength property.

layout

Decides if the label and input should be laid out horizontally or vertically.

When horizontal, the component will try to fill all horizontal space via flex: 1.

Default value is vertical

Testing

The field component generates testids automatically based on their field id. You can override this by providing a data attribute with a custom testid field.

Public Composition

Within the <Field>, the component sets a data-testid attribute on the root element and other public composable components will derive their own testids from it.

For more information on how to use the data attribute, see

This ends up generating the following testids:

  • my-field-1 - Main wrapper element
  • my-field-input-1 - Text input field
  • my-field-label-1 - Label element
  • my-field-description-1 - Description element
  • my-field-message-1 - Message element
  • my-field-help-indicator-1 - Help text tooltip element

Each component also provides a data-balance-component attribute. These are :

  • data-balance-component="field" - Main wrapper element
  • data-balance-component="field-input" - Text input field
  • data-balance-component="field-label" - Label element
  • data-balance-component="field-description" - Description element
  • data-balance-component="field-message" - Message element
  • data-balance-component="field-help-indicator" - Help text tooltip element

Private Composition

If you choose to provide your own instance of <FieldDescription>, <FieldMessage> or <HelpIndicator> inside your <Field> as children, then these will you will need to provide the testid to these yourself.

Without providing a data attribute, the component will not generate testids for these elements.

When you provide your own instances of these components, you can still use the data attribute to generate testids for them. This is useful for testing purposes.

Copyright © 2025 Reckon. Designed and developed in partnership with Thinkmill.
Bitbucket logoJira software logoConfluence logo