FormControl provides context such as isInvalid
, isDisabled
, and isRequired
to form elements.
It follows the WAI specifications for forms.
By passing the isRequired
props, the Input
field has aria-required
set to
true
, and the FormLabel
will show a red asterisk.
Form Libraries like Formik make it soooo easy to manage form state and validation. I 💖 Formik
We've improved the accessibility of the FormControl
component. Here are the
changes:
id
passed to the form control will be passed to the form input directlyFormLabel
will have htmlFor
that points to the id
of the form inputFormErrorMessage
adds aria-describedby
and aria-invalid
pointing to
the form inputFormHelperText
adds/extends aria-describedby
pointing to the form inputisDisabled
, isRequired
, isReadOnly
props passed to FormControl
will
cascade across all related componentsFormLabel
is now aware of the disabled
, focused
and error
state of the
form input. This helps you style the label accordingly using the _disabled
,
_focus
, and _invalid
style props.
If you render FormErrorMessage
and isInvalid
is false
or undefined
,
FormErrorMessage
won't be visible. The only way to make it visible is by
passing isInvalid
and setting it to true
.
Name | Type | Default | Description |
---|---|---|---|
isInvalid | boolean | If true , this prop is passed to its children. | |
isRequired | boolean | If true , this prop is passed to its children. | |
isDisabled | boolean | If true , this prop is passed to its children. | |
isReadOnly | boolean | If true , this prop is passed to its children. |