FormControl

FormControl is a wrapper component to enhance layout with input label, help text, counter or validation message.

Import

import { FormControl } from '@contentful/f36-components';
// or
import { FormControl } from '@contentful/f36-forms';

How to use FormControl

  • FormControl provides context to form elements: isRequired, isDisabled, isInvalid, isReadOnly
  • Compound components of FormControl are: Label, HelpText, ValidationMessage, Counter. These components provide additional visual context and hints for users.
  • For more information on how to use FormControl in Form, check the guide for Form.

Design guidelines

To uphold a consistent look and experience for your application, we recommend following the same design layout guidelines for all inputs:

  • Label is a required element that all your inputs should have to pass the a11y requirements. It should be placed on top of the input, so it would be first in your HTML structure.
  • An input component should follow the label
  • HelpText should appear under the input, when you need to display some additional information to the user
  • ValidationMessage should be appearing directly under the input or under HelpText if displayed, to clearly indicate that it is invalid
  • TextInput and Textarea components can have an option of counting characters. In that case, we recommend aligning HelpText and Counter by using the Flex component and placed them right below the input. Have a look on the example over here

Examples

Basic

With invalid input

Select component with FormControl

Radio Group component with FormControl

Checkbox Group component with FormControl

With character count

Props (API reference)

Open in Storybook

FormControl

Label

HelpText

ValidationMessage

Density support

This component supports multiple densities thanks to the useDensity hook and automatically adjusts its styling for each density (when wrapped with the DensityProvider).