Form container
FormContainer wraps a control with a label and an optional error message, using the same layout as TextField, Select and the other form fields. Use it when you place a custom control in a form and want it to line up with the rest.
Example
Props
FormContainer also accepts the attributes of a div.
Prop | Type | Default value | Description |
|---|---|---|---|
Prop htmlFor * | Type string | Default value required | Description The id of the control the label belongs to |
Prop children * | Type ReactNode | Default value required | Description The control to lay out |
Prop label | Type ReactNode | Default value undefined | Description The label text |
Prop orientation | Type "vertical" | "horizontal" | Default value undefined | Description Whether the label sits above or beside the control |
Prop dir | Type "start" | "end" | Default value undefined | Description Which side of the control the label sits on |
Prop error | Type ReactNode | Default value undefined | Description Error message shown with the control. The label takes the error colour |
Prop addLabelPadding | Type boolean | Default value undefined | Description Adds padding to the label so it lines up with a taller control in a horizontal layout |
* denotes required field
Quick start
import { FormContainer } from '@clickhouse/click-ui'
function ClusterName({ error }: { error?: string }) {
return (
<FormContainer htmlFor='cluster-name' label='Cluster name' error={error}>
<input id='cluster-name' aria-invalid={!!error} />
</FormContainer>
)
}Accessibility
The label is connected to the control through htmlFor, so the control inside must have the matching id and must be a labelable element such as input, select or textarea.
Related components
- Label: The label element FormContainer renders.
- GenericLabel: A label for checkboxes, radios and switches.
- TextField: A text input that already includes this layout.
Common use cases
Horizontal layout with an error
Enter a number between 1 and 65535