Field
Combine labels, controls, and help text to compose accessible form fields and grouped inputs.
Installation
Command to install the Field component.
Component Guide
Use the following to build the Field component.
from components.ui.field import fieldSource Code & Dependencies
For manual installation, copy each of the source codes below in their respective locations.
components/core/core.py
components/ui/separator.py
components/ui/field.py
Composition
field.root
A single control with label, helper text, and validation.
field.root
|- field.label
|- Input / Textarea / switch.root / select.root
|- field.description
\- field.error
field.group
Related fields in one group. Use field.separator between sections when needed.
field.group
|- field.root
| |- field.label
| |- Input / Textarea / switch.root / select.root
| |- field.description
| \- field.error
|- field.separator
\- field.root
|- field.label
\- Input / Textarea / switch.root / select.root
field.set
Semantic grouping with a legend and description, usually containing a field.group.
field.set
|- field.legend
|- field.description
\- field.group
|- field.root
| |- field.label
| |- Input / Textarea / switch.root / select.root
| |- field.description
| \- field.error
\- field.root
|- field.label
\- Input / Textarea / switch.root / select.root
-
field.rootis the core wrapper for a single field. -
field.contentis a flex column that groups label and description. Not required if you have no description. -
Wrap related fields with
field.group, and usefield.setwithfield.legendfor semantic grouping.
Examples
General
Demonstrates field.root, field.group, field.set, field.label, field.description, and field.error composed together.
Props used: orientation on field.root; variant on field.legend; html_for on field.label; data_invalid on field.root.
Responsive Layout
-
Vertical fields: Default orientation stacks label, control, and helper text—ideal for mobile-first layouts.
-
Horizontal fields: Set
orientation="horizontal"onfield.rootto align the label and control side-by-side. Pair withfield.contentto keep descriptions aligned. -
Responsive fields: Set
orientation="responsive"for automatic column layouts inside container-aware parents.
Validation and Errors
-
Add
data_invalid="true"tofield.rootto switch the entire block into an error state. -
Add
aria_invalid="true"on the input itself for assistive technologies. -
Render
field.errorimmediately after the control or insidefield.contentto keep error messages aligned with the field.
field.root(
field.label("Email", html_for="email"),
input(id="email", type="email", aria_invalid="true"),
field.error("Enter a valid email address."),
data_invalid="true",
)
API Reference
field.set
Container that renders a semantic fieldset with spacing presets.
field.set(
field.legend("Delivery"),
field.group(),
)
field.legend
Legend element for a field.set. Switch to the "label" variant to align with standard label sizing.
field.legend("Notification Preferences", variant="label")
The field.legend has two variants: legend and label. The label variant applies standard input label sizing and alignment, which is useful if you are stacking nested fieldsets.
field.group
Layout wrapper that stacks field.root components and enables container queries for responsive orientations.
field.group(
field.root(),
field.root(),
class_name="@container/field-group flex flex-col gap-6",
)
field.root
The core wrapper for a single field. Provides orientation control, invalid state styling, and spacing configurations.
| Prop | Type | Default |
| -------------- | ----------- | ------------ | ------------- | ------------ |
| orientation | "vertical" | "horizontal" | "responsive" | "vertical" |
| class_name | str | |
| data_invalid | str | |
field.root(
field.label("Remember me", html_for="remember"),
switch.root(id="remember"),
orientation="horizontal",
)
field.content
Flex column that groups control and descriptions when the label sits beside the control. Not required if you have no layout description block.
field.root(
checkbox.root(id="notifications"),
field.content(
field.label("Notifications", html_for="notifications"),
field.description("Email, SMS, and push options."),
),
)
field.label
Label styled for both direct inputs and nested field child items.
field.label("Email", html_for="email")
field.title
Renders a standalone title with matching label typography properties inside a field.content node block.
field.content(
field.title("Enable Touch ID"),
field.description("Unlock your device faster."),
)
field.description
Helper text slot that automatically line-balances lengthy strings cleanly when utilized inside horizontal configurations.
field.description("We never share your email with anyone.")
field.separator
Visual divider rule used to separate sections or categories inside a wrapping field.group component. Accepts optional inline children contents.
field.separator("Or continue with")
field.error
Accessible error notification typography container block configured automatically with standard application state layout variables (role="alert").
field.error("Invalid passcode combination provided.")