FormElement
Provides form-related context (ie. required/disabled/readOnly) for building form components, analogous to MUI's [`FormControl`](https://mui.com/material-ui/api/form-control/) component. It is used internally to build UI Kit's form components (eg. `HvInput`, `HvDatePicker`), and can be used to build custom form components.
You probably don’t need to use this component directly. Instead, please check out Related components for a list of ready-to-use UI Kit form components.
HvFormElement
exposes the common properties to be shared between all form components:
required
- Indicates that the form component must be filled out before form submission.disabled
- Indicates that the form component cannot be interacted with.readOnly
- Indicates that the form component cannot be modified.status
- Indicates the validation status of the form component.
Along with the properties above, form components also share the value
/defaultValue
+ onChange
props,
used to control the value of the form component, analogous to the native input
component.
The playground below allows for customization of these properties.
Building blocks
The HvFormElement
component should be constructed using an underlying <input>
component or equivalent (eg. <select>
)
along with the following building blocks provided by UI Kit:
<HvAdornment>
- a decorative icon or action that’s rendered conditionally<HvLabel>
- a recognizable name for a given form element (label
prop)<HvInfoMessage>
- an additional descriptive text for the form element (description
prop)<HvWarningText>
- an error message, displayed only when the form element is in an invalid state (statusMessage
prop)
UI Kit form components will automatically handle the rendering of these building blocks,
whose customization is available via the aforementioned label
/description
/statusMessage
props.
The example below demonstrates how these elements are used in the HvInput
component:
Related components
The following are ready-to-use form components built with HvFormElement
and its building blocks: