Skip to content

Form Field

Form InfrastructureSince 0.2.0

Field chrome and validation for a consumer-owned native <input>, <textarea>, or <select>. FormField adds the label, required indicator, help text, and validation message, maps the browser’s ValidityState to AbsoluteUI’s localized messages, applies the shared message timing, and registers the field with Form. The control element stays yours: it is not cloned or re-created, and only its ARIA wiring and the surrounding chrome are managed.

  • Your control staysWraps a native input, textarea, or select in place without cloning or re-creating it.
  • Complete field chromeAdds the label, required marker, help text, and validation message with correct ARIA wiring.
  • Localized messagesMaps the browser's validity state to consistent AbsoluteUI messages in every browser.
  • Form integrationRegisters with Form, so wrapped native fields validate, submit, and reset with the rest.

Use it for

  • Native controls AbsoluteUI does not render itself: type=number, text-like input types (text, email, url, tel, search, password), a native <select> or <select multiple>, or a <textarea> with native attributes.
  • Progressive enhancement of server-rendered inputs that must keep their element and attributes.
  • Making a plain native element take part in Form validation and the error summary.

Use something else for

  • Text entry with counters, addons, or password reveal: use Text Input or Textarea.
  • Checkboxes, radios, and switches: use Checkbox, Radio Group, or Switch (Form Field rejects them).
  • Date and time values: use Date Input, Date Picker, or Time Picker (date, time, datetime-local, month, and week inputs are rejected).
  • Range sliders and color pickers: range and color inputs are rejected.
  • File uploads: use File Upload.
Anatomy
<div class="aui-field aui-form-field" data-aui-control> (consumer host; children replaced)
<label class="aui-field__label" for=control>Label<span class="aui-field__required" aria-hidden="true">*</span></label>
<input|textarea|select class="aui-form-field__control"> (consumer's element, moved into the host)
<div class="aui-field__description"> (optional)
<div class="aui-field__error aui-validation-message"> (when shown)
</div>

Use the bar above each frame to switch theme, density, direction, and locale.

Form Field in the Employee profile form showcase

Section titled “Form Field in the Employee profile form showcase”

The part of the Employee profile form showcase that uses Form Field. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.

Showcase source
// Forms showcase: an employee profile form that uses every form control together,
// with constraint validation, a cross-field rule, the error summary, reset, and live options.
import { Button } from '@absoluteui/components/button';
import { Checkbox } from '@absoluteui/components/checkbox';
import { CheckboxGroup } from '@absoluteui/components/checkbox-group';
import { Combobox } from '@absoluteui/components/combobox';
import { Fieldset } from '@absoluteui/components/fieldset';
import { Form, type FormSubmitDetail } from '@absoluteui/components/form';
import { FormField } from '@absoluteui/components/form-field';
import { MultiSelect } from '@absoluteui/components/multi-select';
import { NumberInput } from '@absoluteui/components/number-input';
import { RadioGroup } from '@absoluteui/components/radio-group';
import { Select } from '@absoluteui/components/select';
import { Slider } from '@absoluteui/components/slider';
import { Switch } from '@absoluteui/components/switch';
import { TextInput } from '@absoluteui/components/text-input';
import { Textarea } from '@absoluteui/components/textarea';
import { ValidationMessage } from '@absoluteui/components/validation-message';
import { action, annotate, choice, createShowcase, hostIn, toggle } from './kit.js';
const sc = createShowcase({
title: 'Employee profile',
description: 'Every form control in one form: required fields, formats, ranges, a cross-field rule, and an error summary on submit.',
});
const form = document.createElement('form');
form.className = 'sc-form';
form.noValidate = true;
sc.stage.append(form);
// Each fieldset declares its controls, so a component's focus view shows its own group.
const fieldset = (legend: string, description?: string): HTMLFieldSetElement => {
const fs = document.createElement('fieldset');
form.append(fs);
Fieldset.enhance(fs, { legend, ...(description ? { description } : {}) });
return fs;
};
const DEPARTMENTS = [
{ value: 'eng', label: 'Engineering' },
{ value: 'fin', label: 'Finance' },
{ value: 'hr', label: 'People' },
{ value: 'ops', label: 'Operations' },
{ value: 'sales', label: 'Sales' },
];
const MANAGERS = ['Ada Kowalski', 'Bruno Silva', 'Chen Wei', 'Divya Nair', 'Emeka Obi', 'Farah Haddad', 'Grace Liu', 'Hiro Tanaka'].map((name) => ({ value: name.toLowerCase().replace(/\s+/g, '-'), label: name }));
const SKILLS = ['Accessibility', 'Angular', 'Data analysis', 'Design systems', 'Finance', 'Negotiation', 'People management', 'TypeScript'].map((s) => ({ value: s.toLowerCase().replace(/\s+/g, '-'), label: s }));
// Personal details.
const personal = annotate(fieldset('Personal details'), ['form', 'error-summary', 'fieldset', 'text-input', 'textarea', 'form-field']);
const name = TextInput.create(hostIn(personal), { label: 'Full name', name: 'name', required: true, minLength: 2, autocomplete: 'name' });
const email = TextInput.create(hostIn(personal), { label: 'Work email', name: 'email', type: 'email', required: true, autocomplete: 'email', description: 'Used for sign-in and notifications.' });
const phone = TextInput.create(hostIn(personal), { label: 'Phone', name: 'phone', type: 'tel', inputMode: 'tel', pattern: '[+]?[0-9 ]{7,20}', description: 'Digits and spaces, with an optional leading +.' });
const bio = Textarea.create(hostIn(personal), { label: 'About', name: 'bio', maxLength: 280, showCounter: true, rows: 3, resize: 'vertical' });
// A native control labelled and validated by Form Field.
const badge = document.createElement('input');
badge.name = 'badge';
badge.inputMode = 'numeric';
badge.pattern = '[0-9]{6}';
FormField.create(hostIn(personal), { label: 'Badge number', control: badge, description: 'Six digits printed on your badge.' });
// Role.
const role = annotate(fieldset('Role'), ['form', 'error-summary', 'validation-message', 'fieldset', 'select', 'combobox', 'radio-group', 'number-input', 'slider', 'multi-select']);
const department = Select.create(hostIn(role), { label: 'Department', name: 'department', options: DEPARTMENTS, placeholder: 'Choose a department', required: true });
const manager = Combobox.create(hostIn(role), { label: 'Manager', name: 'manager', options: MANAGERS, placeholder: 'Type a name', description: 'Search by first or last name.' });
const type = RadioGroup.create(hostIn(role), { label: 'Employment type', name: 'type', orientation: 'horizontal', required: true, options: [{ value: 'full', label: 'Full time' }, { value: 'part', label: 'Part time' }, { value: 'contract', label: 'Contractor' }] });
const salary = NumberInput.create(hostIn(role), { label: 'Annual salary', name: 'salary', min: 10000, max: 500000, step: 1000, format: { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 } });
const hours = Slider.create(hostIn(role), { label: 'Weekly hours', name: 'hours', min: 8, max: 48, step: 1, largeStep: 4, value: 40, marks: [{ value: 20, label: '20' }, { value: 40, label: '40' }], showValue: true });
const skills = MultiSelect.create(hostIn(role), { label: 'Skills', name: 'skills', options: SKILLS, maxSelected: 5, description: 'Up to five.' });
// Preferences.
const prefs = annotate(fieldset('Preferences', 'You can change these later in settings.'), ['form', 'error-summary', 'fieldset', 'checkbox-group', 'switch', 'checkbox']);
const benefits = CheckboxGroup.create(hostIn(prefs), { label: 'Benefits', name: 'benefits', orientation: 'horizontal', options: [{ value: 'health', label: 'Health' }, { value: 'pension', label: 'Pension' }, { value: 'transit', label: 'Transit pass' }, { value: 'gym', label: 'Gym' }] });
const remote = Switch.create(hostIn(prefs), { label: 'Works remotely', name: 'remote' });
const terms = Checkbox.create(hostIn(prefs), { label: 'I confirm these details are correct', name: 'terms', required: true });
// A standalone validation message for a rule that is not tied to one control.
const actions = annotate(hostIn(form), ['form', 'error-summary', 'validation-message']);
actions.className = 'sc-form__actions';
const hint = ValidationMessage.create(hostIn(actions), { tone: 'info', message: 'Part-time employees work at most 32 hours per week.' });
const buttons = hostIn(actions);
buttons.className = 'sc-form__buttons';
const submit = Button.create({ text: 'Save profile', variant: 'primary', type: 'submit' }, document);
const reset = Button.create({ text: 'Reset', variant: 'secondary', type: 'reset' }, document);
buttons.append(submit.element, reset.element);
const formController = Form.create(form, {
summaryTitle: 'Fix these fields to save the profile',
rules: [
{
fields: ['type', 'hours'],
validate: (values) => (values.type === 'part' && Number(values.hours) > 32 ? 'Part-time employees work at most 32 hours per week.' : null),
},
],
});
form.addEventListener('aui-submit', (e) => {
const { values } = (e as CustomEvent<FormSubmitDetail>).detail;
submit.setLoading(true);
// A save takes a moment; the button stays busy and focusable meanwhile.
setTimeout(() => {
submit.setLoading(false);
hint.update({ tone: 'success', message: `Saved the profile of ${typeof values.name === 'string' ? values.name : 'the employee'}.` });
}, 600);
});
form.addEventListener('aui-reset', () => {
hint.update({ tone: 'info', message: 'Part-time employees work at most 32 hours per week.' });
});
sc.listen(form, ['aui-submit', 'aui-invalid', 'aui-reset'], 'form');
for (const [label, host] of [
['name', name.host],
['email', email.host],
['department', department.host],
['manager', manager.host],
['type', type.host],
['salary', salary.host],
['hours', hours.host],
['skills', skills.host],
['benefits', benefits.host],
['remote', remote.host],
['terms', terms.host],
] as const) {
sc.listen(host, ['aui-change'], label);
}
// Options.
const all = [name, email, phone, bio, department, manager, type, salary, hours, skills, benefits, remote, terms];
toggle(sc, 'Disabled', false, (disabled) => {
for (const c of all) c.update({ disabled });
badge.disabled = disabled;
submit.update({ disabled });
});
toggle(sc, 'Read-only', false, (readOnly) => {
for (const c of [name, email, phone, bio, department, manager, salary, skills]) c.update({ readOnly });
badge.readOnly = readOnly;
});
choice(
sc,
'Validate',
[
{ value: 'blur', label: 'When leaving a field' },
{ value: 'input', label: 'While typing' },
{ value: 'submit', label: 'On submit only' },
],
'blur',
(timing) => {
for (const c of [name, email, phone, bio, department, type, salary, benefits, terms]) c.update({ validationTiming: timing });
},
);
action(sc, 'Fill sample data', () => {
name.setValue('Ada Lovelace');
email.setValue('ada@example.com');
phone.setValue('+44 20 7946 0000');
bio.setValue('Writes the first programs and reviews every pull request.');
badge.value = '204816';
department.setValue('eng');
manager.setValue('chen-wei');
type.setValue('full');
salary.setValue(86000);
hours.setValue(38);
skills.setValue(['typescript', 'accessibility']);
benefits.setValue(['health', 'pension']);
remote.setChecked(true);
terms.setChecked(true);
sc.log('sample data filled');
});
action(sc, 'Submit empty', () => {
formController.reset();
formController.submit();
}, ['form', 'error-summary']);
import { FormField } from '@absoluteui/components/form-field';
const control = document.createElement('input');
control.name = 'zip';
control.inputMode = 'numeric';
control.autocomplete = 'postal-code';
control.pattern = '[0-9]{5}';
const host = document.createElement('div');
document.body.append(host);
const zip = FormField.create(host, { label: 'ZIP code', control, required: true, description: 'Five digits' });
host.addEventListener('aui-change', () => {
host.dataset.valid = String(zip.validity.valid);
});

Native select and textarea with consumer validation

Section titled “Native select and textarea with consumer validation”
import { FormField, type FormFieldChangeDetail } from '@absoluteui/components/form-field';
const topic = document.createElement('select');
topic.name = 'topic';
topic.add(new Option('Choose a topic', ''));
topic.add(new Option('Billing', 'billing'));
topic.add(new Option('Technical support', 'support'));
const topicHost = document.createElement('div');
document.body.append(topicHost);
FormField.create(topicHost, { label: 'Topic', control: topic, required: true });
const details = document.createElement('textarea');
details.name = 'details';
details.maxLength = 500;
const detailsHost = document.createElement('div');
document.body.append(detailsHost);
FormField.create(detailsHost, {
label: 'Details',
control: details,
validate: (value) => (typeof value === 'string' && /https?:\/\//.test(value) ? 'Remove links from your message.' : null),
});
detailsHost.addEventListener('aui-input', (event) => {
const { validity } = (event as CustomEvent<FormFieldChangeDetail>).detail;
detailsHost.dataset.valid = String(validity.valid);
});

Enhance server-rendered markup and refresh after programmatic changes

Section titled “Enhance server-rendered markup and refresh after programmatic changes”
import { FormField } from '@absoluteui/components/form-field';
const host = document.querySelector<HTMLElement>('#quantity-field');
const control = host?.querySelector<HTMLInputElement>('input[type="number"]');
if (host && control) {
const quantity = FormField.create(host, { label: 'Quantity', control });
// Native attributes are the constraints; re-read them after changing them in code.
control.max = '10';
control.value = '12';
quantity.refresh();
quantity.reportValidity();
}
import { configureAbsoluteUI } from '@absoluteui/core';
import '@absoluteui/components/form-field';
configureAbsoluteUI({ components: { formField: { validationTiming: 'input' } } });
Terminal window
npm install @absoluteui/components @absoluteui/core @absoluteui/theme

Registry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.

import { FormField } from '@absoluteui/components/form-field';
import '@absoluteui/components/form-field/style.css';
import { FormField } from '@absoluteui/components/form-field';
import '@absoluteui/components/form-field/style.css';
const host = document.querySelector<HTMLElement>('#guests-field');
const control = host?.querySelector<HTMLInputElement>('input[name="guests"]');
if (host && control) {
const guests = FormField.create(host, { label: 'Number of guests', control, required: true, description: 'Up to 8 people' });
host.addEventListener('aui-change', () => {
if (!guests.validity.valid) guests.reportValidity();
});
}
More usage
import { FormField } from '@absoluteui/components/form-field';
const control = document.createElement('input');
control.name = 'zip';
control.pattern = '[0-9]{5}';
const host = document.createElement('div');
document.body.append(host);
FormField.create(host, { label: 'ZIP code', control, required: true, description: 'Five digits' });

Using Angular? See Form Field for Angular.

FormField.create(host: HTMLElement, options: FormFieldOptions): FormField

Global configuration key: formField (see Configuration).

Option Type Default Description
label string Visible label and accessible name (<label for> the control). Required.
control HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement The native control to wrap; moved into the host. It receives an id if it has none. Choice, file, hidden, button, date/time (date, time, datetime-local, month, week), range, and color input types are rejected. Required. Set at creation only.
hideLabel boolean false Visually hide the label; it remains the accessible name.
description string Help text referenced by aria-describedby.
required boolean Sets the native required property and the indicator. When omitted, the control’s own required attribute is used.
validate (value: string | string[]) => string | null Consumer validation after native constraints; return a message to mark the value invalid. string[] for <select multiple>.
icons Partial<{ error: IconRef }> Icon slot overrides.
validationTiming 'blur' | 'input' | 'submit' "blur" When validation messages first appear; afterwards they update live. Globally configurable.
locale string "en-US" Message and number-formatting locale. Globally configurable. Inherited from common configuration.
Property Type Description
host HTMLElement Consumer host; its children are replaced by the chrome and the control.
control FormFieldControl The wrapped native control.
value string | string[] Current value; string[] for <select multiple>.
name string | null The control’s name, or null when empty.
label string Label text.
disabled boolean The control’s disabled property.
validity FieldValidity { valid, error, message }; recomputed on each render.
dirty boolean Value differs from the value at creation.
touched boolean Focus has left the control at least once.
Method Description
refresh(): void Re-read native constraints, setCustomValidity() state, and the value after changing them in code.
update(options: Partial<Omit<FormFieldOptions, 'control'>>): void Merge and apply options.
reportValidity(): boolean Show messages now (marks the field submitted) and return validity.
setCustomError(message: string | null): void External error (server, cross-field rule); cleared when the user types. null or ‘’ clears it.
getFormValue(): string | string[] Value for form serialization.
focus(): void Focus the control.
reset(): void Restore the value (or selected options) captured at creation and clear dirty/touched/submitted/custom-error state.
destroy(): void Remove the chrome, listeners, registration, and subscription; restore the consumer’s aria-describedby. The control stays in the host.
Event Detail Bubbles Cancelable Description
aui-input { value: string | string[]; validity: FieldValidity } Yes No Native input event on the control.
aui-change { value: string | string[]; validity: FieldValidity } Yes No Native change event on the control.
Area Description
control The consumer’s native element, placed between the label and the help text.

All rules live in the aui.components cascade layer, so application styles override them without specificity battles.

Class Purpose
aui-field aui-form-field Host.
aui-form-field--invalid Host modifier while a message is shown.
aui-field__label | __required | __description | __error Shared field chrome.
aui-form-field__control Added to the native control: AbsoluteUI control surface.
Slot Default icon
error alert-circle

Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.

--aui-border-width | --aui-color-border | --aui-color-border-strong | --aui-color-disabled-bg | --aui-color-error-fg | --aui-color-focus-ring | --aui-color-surface | --aui-color-surface-sunken | --aui-color-text | --aui-color-text-disabled | --aui-color-text-muted | --aui-control-height-md | --aui-control-padding-x | --aui-duration-fast | --aui-easing-standard | --aui-focus-ring-width | --aui-font-family-sans | --aui-font-size-md | --aui-font-size-sm | --aui-font-weight-medium | --aui-icon-size-sm | --aui-line-height-normal | --aui-line-height-tight | --aui-radius-md | --aui-space-1 | --aui-space-2

TypeScript definitions
type FormFieldControl = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
type FormFieldValue = string | string[];
interface FormFieldIcons { error: IconRef }
interface FormFieldChangeDetail { value: FormFieldValue; validity: FieldValidity }
interface FormFieldOptions {
label: string;
control: FormFieldControl;
hideLabel?: boolean;
description?: string;
required?: boolean;
validate?: (value: FormFieldValue) => string | null;
validationTiming?: ValidationTiming;
locale?: string;
icons?: Partial<FormFieldIcons>;
}

Pattern: Native form control with a <label for> association (HTML); the consumer’s element keeps its native role.

Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.

Key Context Action
Tab / Shift+Tab Any Moves focus to and from the control.
All native keys Control focused Native behavior of the element (editing, arrow stepping, select picker).
Element Role
control Native role of the wrapped element (textbox, spinbutton, combobox/listbox for <select>, …)
error icon none (aria-hidden=true)
Attribute Element Value
aria-describedby control Help text and visible error ids, followed by ids the consumer had set before creation
aria-invalid control “true” only while an error message is shown
required control Native attribute, set from the required option when given

The control shows the shared control focus indicator (border in color-focus-ring plus a ring); forced-colors mode uses a Highlight outline.

Criterion Level Note
1.3.1 Info and Relationships A
1.4.3 Contrast (Minimum) AA
1.4.11 Non-text Contrast AA
2.1.1 Keyboard A
2.4.7 Focus Visible AA
2.5.3 Label in Name A
3.3.1 Error Identification A
3.3.2 Labels or Instructions A
3.3.3 Error Suggestion AA
4.1.2 Name, Role, Value A

Automated test results: Accessibility and compliance.

  • The required asterisk is aria-hidden; the native required attribute conveys the state.
  • Native validation bubbles are suppressed (the invalid event is prevented) so only the AbsoluteUI message is shown and read.
  • Errors appear after the first blur by default; when focus left because a pointer was pressed elsewhere, the message renders after the pointer is released so the click is not displaced.
  • Existing aria-describedby references (for example an external hint) are kept and restored on destroy.
  • Behavior with every native input type has not been manually verified with NVDA, JAWS, and VoiceOver.
Import cost Minified gzip brotli CSS brotli
@absoluteui/components/form-field 41.2 kB 14.0 kB 12.4 kB 0.7 kB

Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.

Budget (enforced in CI) Limit
FormField.create No dedicated performance test; one render per input/change/blur event

Tested scale: Unit tests cover single fields of each supported element type.

Four listeners on the control (input, change, blur, invalid) and one configuration subscription. Each event re-renders the chrome once. No dedicated performance budget.

Measured run times: Performance.

States

default, focus-visible, filled, disabled, read-only, required, invalid (message shown).

State transitions
From Trigger To
pristine user edits dirty; message shown only with validationTiming: 'input'
any control blurs touched; messages shown (blur timing), deferred until pointer release when a pointer caused the blur
any reportValidity() (for example on form submit) submitted; messages shown for every timing
invalid (custom error) user types custom error cleared, validity recomputed
any reset() value at creation; pristine, untouched
Accessibility notes
  • The required asterisk is aria-hidden; the native required attribute conveys the state.
  • Native validation bubbles are suppressed (the invalid event is prevented), so only the AbsoluteUI message is shown and read.
  • Errors appear after the first blur by default. When the blur was caused by pressing a pointer elsewhere, the message renders after the pointer is released so a click on Submit is not displaced.
  • Missing values on a <select> use “Select an option.”; text-like controls use “This field is required.”
  • Manual screen-reader verification is pending (see Known limitations).
Responsive behavior

The control fills its container (inline-size: 100%, min-inline-size: 0). Textareas resize vertically. Density tokens change the control height.

Right-to-left

Follows the document direction; the chrome uses logical properties.

Theming

Role tokens through the shared control-surface and text-control-states mixins; a <select> keeps its native picker and only the closed control is styled. In forced-colors mode, focus draws a Highlight outline.

Global configuration
configureAbsoluteUI({ components: { formField: { validationTiming: 'input' } } });

Changes apply to existing instances immediately.

Component configuration

Instance options override global and theme defaults. All options except control are dynamic.

Icons

icons.error (default alert-circle).

Security

All text uses textContent. Validation messages never include the entered value, only constraint parameters. The consumer’s element is not cloned, so its listeners and attributes survive. CSP-safe.

Data handling

No persistence, network access, or telemetry. The native control carries its own value for form submission.

Supported data scale

One control per field. Unit tests cover each supported element type; large forms are expected to scale linearly.

Edge cases
  • Native minlength/maxlength apply only after user edits in browsers; Form Field also enforces them for programmatic values (counted in code points).
  • <select multiple> values are string[]; dirty compares the selected values with those at creation.
  • required omitted keeps the control’s own attribute; required: false removes it.
  • destroy() leaves the generated id and the required value on the control.
  • Numeric min, max, and step are read from the attributes; step="any" disables step checking. The step base follows HTML: min, else the value attribute, else 0.
  • A native setCustomValidity(message) takes precedence over every other check and yields error custom with the native validationMessage (the consumer validate callback does not run). Call setCustomValidity('') and then refresh() to clear it.
Errors
Code Category Cause
FORM_FIELD_OPTIONS configuration Missing or blank label; control is not an input, textarea, or select; or the input type is checkbox, radio, file, hidden, button, submit, reset, image, date, time, datetime-local, month, week, range, or color (use Checkbox, Radio Group, Switch, Date Input, Date Picker, or Time Picker).
Validation (validity.error) validation value-missing, type-mismatch, too-short, too-long, pattern-mismatch, bad-input, range-underflow, range-overflow, step-mismatch, custom.

A failed construction leaves the host and the control untouched.

Known limitations
  • After changing constraint attributes or the value in code, call refresh().
  • The initial value for dirty and reset() is captured at creation.
  • No character counter.
  • Screen-reader behavior across native input types has not yet been manually verified with NVDA, JAWS, and VoiceOver.
Unsupported scenarios
  • checkbox, radio, file, hidden, button, submit, reset, image, date, time, datetime-local, month, week, range, and color inputs.
  • More than one control per field.
  • HTML in the label, help text, or messages.