Base Field
An unstyled form field coordinating labels, descriptions, built-in and async validation, and accessible error bindings.
Base Field pairs a single form control with its Label, Description, Error, and Validity readers, automatically managing ARIA relationships along with built-in and versioned asynchronous validation.
Preview
Section titled “Preview”Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases. Import fieldRoot, fieldLabel, fieldControl, fieldDescription, fieldError, fieldValidity, and the asFieldControl / asFieldTextControl bridges from @proto.ui/prototypes-base/field.
Anatomy
Section titled “Anatomy”Each Root groups one Control with an optional Label, Description, Error, and any number of passive Validity readers (nested Root instances stay isolated):
Root: manages validation and interaction states (invalid,pending,dirty,touched,filled,focused,disabled,readOnly,required) and exposesvalidate(reason?),resolveValidation(requestId, result),cancelValidation(),resetValidation(),focusControl(options?), andgetValidity().Control: renders a single-line text input by default, or useasFieldControlto integrate custom controls (such as checkboxes or radio groups) with field validation and label focus.Label: linksaria-labelledbyto the control and focuses it on pointer activation whenactivation={true}(default).Description: passive help text linked viaaria-describedby.Error: links viaaria-errormessagewhen invalid, rendering explicitmessage, currenterrors, or a fallback message. Unmounts content when closed by default (setkeepMountedto keep it mounted and hidden). Compose aLiveRegionwhen spoken announcements are needed.Validity: passive reader exposing the currentgetValidity()snapshot.
Built-in and async validation
Section titled “Built-in and async validation”- Built-in constraints support
required,minLength, andmaxLength(measured in UTF-16 code units), triggered according tovalidationMode('onBlur','onChange', or'manual').'onChange'waits until IME composition ends (compositionend). requiredtreatsnull,false,'', and empty arrays as empty (0and whitespace count as filled with no implicit trimming). Empty optional strings bypass length bounds.- With
externalValidation={true}, passing built-in checks emitsvalidationRequestwith{ requestId, value, reason }. Resolve it viaresolveValidation(requestId, { invalid, errors }); stale results from changed values, newer requests, resets, or policy switches are ignored automatically. - Pass
invalid/errorsfor controlled validation:validityChangenotifies your application so you can supply updated props.resetValidation()clears validation andtouchedwithout altering the control value ordirtybaseline.
Accessibility
Section titled “Accessibility”Field automatically links and cleans up aria-labelledby, aria-describedby, aria-errormessage, aria-required, aria-invalid, aria-busy, and aria-readonly without requiring manual DOM IDs.
Root Props
Section titled “Root Props”Passing invalid or errors controls the validation state.
| Prop | Type | Default |
|---|---|---|
invalid | boolean | — |
errors | string[] | — |
defaultInvalid | boolean | false |
defaultErrors | string[] | [] |
disabled | boolean | false |
readOnly | boolean | false |
required | boolean | false |
minLength | number | -1 |
maxLength | number | -1 |
validationMode | 'onBlur' 'onChange' 'manual' | onBlur |
externalValidation | boolean | false |
Other parts
Section titled “Other parts”- Label:
activationdefaults totrue. - Control: accepts text input props:
value/defaultValue,placeholder,name,autoComplete, andariaLabeldefault to'';disabled,readOnly, andrequireddefault tofalse; optionalinputModeandenterKeyHint. - Error:
messagedefaults to''andkeepMountedtofalse. - Description, Validity: no props.