Field
Wires a label, a description and validation errors to a form control.
FieldError shows the control’s native validation message once the field is invalid,
after the first submit or once the person leaves the field. Submit the form empty to see it.
Field sets and horizontal fields
Group related fields in a FieldSet with a FieldLegend, and stack them in a FieldGroup.
orientation="horizontal" puts a checkbox or switch beside its label; wrap the label and a
description in FieldContent to keep them together.
Dependencies
What it's built from and what's built from it in Base, read from the imports in its source.
| Uses | Labelform itemTextprimitive |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20 |
Installation
Set the project up for Base once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Base's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
Field
Wires a label, a description and errors to the control inside it.
- orientationours
horizontalputs the control beside its label, for a checkbox or a switch.Type "horizontal" | "vertical" · Default vertical
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: FieldState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: FieldState) => string)
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- disabled
Disables the control, and marks every part.
Type boolean
- invalid
Whether the field shows as invalid, when your code decides, like a form library or an error from the server.
trueshows its errors now,falseshows none whatever the browser thinks. Leave it out to show the browser's own validation once a submit finds the field invalid.Type boolean
- name
The name the control submits under, when the control doesn't set its own.
Type string
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<FieldState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: FieldState) => CSSProperties)
FieldContent
The label and description beside a horizontal field's control.
Takes the props of a native div.
FieldDescription
Extra help for the field, read out with its control.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: FieldDescriptionState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: FieldDescriptionState) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<FieldDescriptionState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: FieldDescriptionState) => CSSProperties)
FieldError
Shows the control's validation error once it's invalid.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: FieldErrorState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: FieldErrorState) => string)
- match
When this error shows.
trueshows it always andfalsenever. A validity flag, like"valueMissing", shows it only for that problem of the browser's own validation. Without it, any problem shows it.Type boolean | ValidityKey
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<FieldErrorState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: FieldErrorState) => CSSProperties)
FieldGroup
Stacks fields, or a group of checkboxes or switches sharing one label.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
FieldLabel
Names the field's control.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: FieldState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: FieldState) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<FieldState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: FieldState) => CSSProperties)
FieldLegend
Names a field set.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: FieldSetState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: FieldSetState) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<FieldSetState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: FieldSetState) => CSSProperties)
FieldSet
Related fields under one legend, like an address.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: FieldSetState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: FieldSetState) => string)
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- disabled
Disables every control inside it, except those in its legend, and leaves them out of the form.
Type boolean
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<FieldSetState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: FieldSetState) => CSSProperties)