Skip to main content

TextField

BasicInputs<co-text-field>

TextField is a labelled one-line input with masks for phone, SSN, NPI, ZIP and EIN, plus error, helper, required and read-only lock states.

import { TextField } from 'health-components';

Examples​

Showcase​

Storybook

Masks​

Storybook

With Error​

Storybook

Read Only​

Storybook

Sizes​

Storybook

Usage​

<TextField label="Mobile Phone" mask="phone" required value={phone} onChange={setPhone} error={errors.phone} />
<TextField label="Member ID" value={memberId} readOnly={access === "view"} />

When to use​

  • Short free text and identifiers: name, phone, member ID, NPI, policy number.

When not to use​

  • Choosing from a known list: Select or Combobox.
  • Dates: DatePicker.
  • More than one line: TextArea.

Variants and states​

VariantWhat it is
mask phone(###) ###-####, numeric keypad on phones.
mask ssn###-##-####. Show only the last four after save.
mask npi10 digits.
mask zip5 digits or ZIP+4.
mask einXX-XXXXXXX.
errorRed border plus the message under the field, role alert.
helperMuted hint under the field.
requiredRed asterisk after the label plus aria-required.
readOnly lockGrey fill, lock icon and "Your role can view but not edit" under the field.
sizessm 30px, md 36px, lg 48px (kiosk).

Accessibility​

  • Every field has a visible label; placeholder is an example, never the label.
  • Error and helper text are linked with aria-describedby; aria-invalid is set on error.
  • A mask only arranges digits into the pattern. It proves the shape, not that the NPI or ZIP is real; check those on save and say so in the error ("This NPI is not in NPPES").
  • Input borders use border, which is below 3:1 on surface in every light style (source value kept). The label and the field fill carry the boundary; see README, Accessibility.

Do and don't​

  • Do: Error text names the field and the fix: "Enter the EIN as XX-XXXXXXX."
  • Do: Read-only for a biller viewing demographics: lock state, value still selectable and copyable.
  • Don't: "Invalid input".
  • Don't: Hiding a field the role can view: that is the view level, so lock it; hide only at the none level.

Props​

PropTypeDefaultDescription
label *string—Visible label; required
maskMaskKindnone'phone' | 'ssn' | 'npi' | 'zip' | 'ein' | 'date'
valuestringundefined (uncontrolled)Controlled value
defaultValuestring""Initial value (uncontrolled), formatted with the mask
onChange(value: string, event: ChangeEvent<HTMLInputElement>) => voidnoneCalled with the (masked) value and the change event
errorstringnoneError message: red border, message under the field with role alert, aria-invalid
helperstringthe mask hintMuted hint under the field
requiredbooleanfalseRed asterisk plus aria-required
readOnlybooleanfalseRead-only lock state: grey fill, lock icon and lock message
lockMessagestring'Your role can view but not edit'Lock line text when readOnly
sizeTextFieldSize'md''sm' 30px | 'md' 36px | 'lg' 48px (kiosk)
iconLeftIconNamenoneIcon inside the input on the left
suffixstringnoneUnit text inside the input on the right, such as "units"
styleCSSProperties—Inline style of the root

Also accepts native attributes, including defaultChecked, autoFocus, onInput, type, disabled, name, max, step, placeholder, accept, autoComplete, checked, maxLength, min, multiple, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-text-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-text-field label="…" mask="…" [style]="style" (co-change)="onChange($event.detail)"></co-text-field>
KindNameDescription
attributelabelVisible label; required
attributemask'phone' | 'ssn' | 'npi' | 'zip' | 'ein' | 'date'; default none
attributevalueControlled value; default undefined (uncontrolled)
attributedefault-value / defaultValueInitial value (uncontrolled), formatted with the mask; default ""
attributeerrorError message: red border, message under the field with role alert, aria-invalid; default none
attributehelperMuted hint under the field; default the mask hint
attributerequiredRed asterisk plus aria-required; default false
attributeread-only / readOnlyRead-only lock state: grey fill, lock icon and lock message; default false
attributelock-message / lockMessageLock line text when readOnly; default 'Your role can view but not edit'
attributesize'sm' 30px | 'md' 36px | 'lg' 48px (kiosk); default 'md'
attributeicon-left / iconLeftIcon inside the input on the left; default none
attributesuffixUnit text inside the input on the right, such as "units"; default none
property / JSON attributestyleInline style of the root
attributedefault-checked / defaultChecked
attributeauto-focus / autoFocus
property / JSON attributetype
attributedisabled
attributename
property / JSON attributemax
property / JSON attributestep
attributeplaceholder
attributeaccept
property / JSON attributeauto-complete / autoComplete
attributechecked
attributemax-length / maxLength
property / JSON attributemin
attributemultiple
eventco-changeCalled with the (masked) value and the change event; default none (React: onChange)
eventco-input (React: onInput)