TextInput
A single-line text input, and also the base for input components such as MultilineTextInput, NumberInput and SearchInput.
Basic usage
Passing value makes it controlled; otherwise the component maintains its own input state and defaultValue is only the initial value. onChange uses the value-first signature — the first argument is the new string value.
Type
type decides both the <input>'s type attribute and the root's oo-ui-textInputWidget-type-{type} class. It is limited to the theme-styled whitelist text, password, email, url, number, search; an invalid value falls back to text.
Label
label is the field label text; labelPosition puts it before (before) or after (after, the default) the input. To hide the label visually, turn on invisibleLabel: the accessible name is kept, and title falls back to the label text when not given explicitly.
Writing the label on the input itself suits standalone placement; in a form, the label, alignment and "click label to focus the input" linkage are usually delegated to FieldLayout, and the field control itself does not set label.
Icons and indicators
icon renders on one side of the input (see Icon), indicator on the other (see Indicator). When indicator is not given explicitly and required is true, it falls back to the required indicator.
Soft validation
validate is soft feedback: when the value fails, the input element gets aria-invalid and the root gets an invalid flag class, but the value is not rewritten. By default only native browser constraints (e.g. required) take part in submit validation. It fires on value change (debounced 250ms), on blur, and clears on focus.
validate accepts three forms: a regular expression (tested with test), a function (returning a boolean or Promise<boolean>), or the symbolic names 'non-empty' (non-empty) and 'integer' (digits only).
Disabled and read-only
disabled outputs oo-ui-widget-disabled and aria-disabled (not the native disabled); the input can't be focused or typed into. readOnly keeps focus and text selection/copying, and only forbids edits.
Where props land
The root is a <div> and the input element is an <input>. Three landing rules (common to all input components):
...restfrom props (undeclared attributes likeid,className,data-*) lands on the root div; attributes that must go on the native<input>(such asrole,aria-*,autoComplete) must go through theinputPropschannel.inputRefpoints to the inner<input>(the componentrefpoints to the root div); useinputRefto focus the input.tabIndex,title,dirandaccessKeyare taken over by the component and land directly on the<input>(matching the original's landing spots), not viarest.
onChange / onBlur / onFocus in inputProps are chained after the component's own logic, so they don't truncate the value pipeline or soft validation.
API
When required is true, this library also outputs aria-required on the native <input> (the original only writes the native required attribute). This covers the TextInput inheritance line (MultilineTextInput, NumberInput and ComboBoxInput alike); non-text forms (Dropdown, Checkbox, Radio, SelectFile) do not output it.
See also
- How values flow between the component and your state: Controlled and uncontrolled
- The pass-through and
refrules shared by all components: Common props - The multiline, number and search forms: MultilineTextInput, NumberInput,
SearchInput