FormControl
is a wrapper component to enhance layout with input label, help text, counter or validation message.
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 userValidationMessage
should be appearing directly under the input or underHelpText
if displayed, to clearly indicate that it is invalidTextInput
andTextarea
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
Usage examples
Basic example
Example with invalid input
Example of Select component with FormControl
Example of Radio Group component with FormControl
Example of Checkbox Group component with FormControl
Example with character count
Props
FormControl
- Name
children(required)
ReactNode - Name
as
HTML Tag or React Component (e.g. div, span, etc) - Name
className
DescriptionCSS class to be appended to the root element
string - Name
id
string - Name
inputValue
Descriptionvalue from text input and textarea to used for counting characters
string - Name
isDisabled
DescriptionIf `true` set the form control to the disabled state.
falsetrue - Name
isInvalid
DescriptionIf `true` set the form control to the invalid state.
falsetrue - Name
isReadOnly
DescriptionIf `true` set the form control to the read only state.
falsetrue - Name
isRequired
DescriptionIf `true` set the form control to be required.
falsetrue - Name
margin
Descriptionsets margin to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginBottom
Descriptionsets margin-bottom to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginLeft
Descriptionsets margin-left to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginRight
Descriptionsets margin-right to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginTop
Descriptionsets margin-top to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
maxLength
DescriptionMax length of characters used for the text input and textarea
number - Name
setInputValue
DescriptionSet input value function
Dispatch<SetStateAction<string>> - Name
setMaxLength
DescriptionSet max length function
Dispatch<SetStateAction<number>> - Name
testId
DescriptionA [data-test-id] attribute used for testing purposes
string