Skip to main content

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​

Storybook

With Id​

Storybook

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​

VariantWhat it is
label13px medium label, linked to the control with htmlFor.
requiredRed asterisk after the label; the control sets aria-required.
helperMuted hint under the control.
errorRed message under the control, role alert. Replaces the helper.
lockLock 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's id, or use the function child to receive it.
  • Error, helper and lock lines have ids linked with aria-describedby (fieldDescribedBy builds 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​

PropTypeDefaultDescription
idstringgeneratedid of the control inside; the label points at it and the help, error and lock ids derive from it
labelReactNodenoneVisible label
requiredbooleanfalseRed asterisk after the label (the control sets aria-required)
errorReactNodenoneError message under the control, role alert; replaces the helper
helperReactNodenoneMuted hint under the control
lockReactNodenoneRead-only lock line with a lock icon ("Your role can view but not edit")
classNamestring—Class on the root
styleCSSProperties—Inline style of the root
childrenReactNode | ((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>
KindNameDescription
attributeidid of the control inside; the label points at it and the help, error and lock ids derive from it; default generated
attributerequiredRed asterisk after the label (the control sets aria-required); default false
attributeclass-name / classNameClass on the root
property / JSON attributestyleInline style of the root
slotlabelVisible label; default none Plain text also works as the `label` attribute.
sloterrorError message under the control, role alert; replaces the helper; default none Plain text also works as the `error` attribute.
slothelperMuted hint under the control; default none Plain text also works as the `helper` attribute.
slotlockRead-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