Field
BasicInputs
<co-field>Field is the labelled wrapper every form control shares: the label with its required marker, the control, then a read-only lock line and an error or helper line under it.
import { Field } from 'health-components';
Examples
States
With Id
Usage
<Field label="Arrival Time" required helper="Clinic local time" error={errors.time}>
{(control) => <input type="time" className="co-inp" {...control} />}
</Field>
When to use
- Wrapping a control that has no CareOS component of its own (a native time input, a custom widget) so it lines up with the other fields in a form.
When not to use
- A plain text, select, date or search field: use TextField, Select, DatePicker or Combobox, which already include Field.
- Checkboxes and radios: they carry their own label (Checkbox, RadioGroup).
Variants and states
| Variant | What it is |
|---|---|
| label | 13px medium label, linked to the control with htmlFor. |
| required | Red asterisk after the label; the control sets aria-required. |
| helper | Muted hint under the control. |
| error | Red message under the control, role alert. Replaces the helper. |
| lock | Lock icon and "Your role can view but not edit" under the control, for read-only fields. |
Accessibility
- The label points at the control with
htmlFor; pass the control'sid, or use the function child to receive it. - Error, helper and lock lines have ids linked with aria-describedby (
fieldDescribedBybuilds the value); aria-invalid is set on error. - The asterisk is aria-hidden; the control carries aria-required.
Do and don't
- Do: Error text names the field and the fix: "Choose a place of service."
- Do: Lock a field the role can view but not edit, and keep the value selectable.
- Don't: Use the placeholder as the label.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | generated | id of the control inside; the label points at it and the help, error and lock ids derive from it |
label | ReactNode | none | Visible label |
required | boolean | false | Red asterisk after the label (the control sets aria-required) |
error | ReactNode | none | Error message under the control, role alert; replaces the helper |
helper | ReactNode | none | Muted hint under the control |
lock | ReactNode | none | Read-only lock line with a lock icon ("Your role can view but not edit") |
className | string | — | Class on the root |
style | CSSProperties | — | Inline style of the root |
children | ReactNode | ((control: FieldControlProps) => ReactNode) | — | The control, or a function that receives id and aria attributes to spread on it |
Every component also accepts className.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-field>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.
Angular template
<co-field id="…" required [style]="style">…</co-field>
| Kind | Name | Description |
|---|---|---|
| attribute | id | id of the control inside; the label points at it and the help, error and lock ids derive from it; default generated |
| attribute | required | Red asterisk after the label (the control sets aria-required); default false |
| attribute | class-name / className | Class on the root |
| property / JSON attribute | style | Inline style of the root |
| slot | label | Visible label; default none Plain text also works as the `label` attribute. |
| slot | error | Error message under the control, role alert; replaces the helper; default none Plain text also works as the `error` attribute. |
| slot | helper | Muted hint under the control; default none Plain text also works as the `helper` attribute. |
| slot | lock | Read-only lock line with a lock icon ("Your role can view but not edit"); default none Plain text also works as the `lock` attribute. |
| slot | (default) | The control, or a function that receives id and aria attributes to spread on it |