Text field
Filled or outlined text input with a floating label, icons, affixes, counter, error icon and a text area.
import { TextField } from '@windmorph/react';Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the input, then to a trailing icon button if there is one, and on to the next element. |
| Enter | Submits the enclosing form from a single-line field, as a native input does. In a multiline field it starts a new line. |
Typing, selection, paste and undo are the browser's own: the field is a native <input>, or a <textarea> with multiline.
Screen reader
- Role
- A native text
input, or atextareawithmultiline, labelled by a<label>(React AriauseTextField). - Accessible name
- The visible
label, with a*whenrequired; without one,aria-labeloraria-labelledby. One of the three is required. - States announced
- Required (
aria-required), invalid (aria-invalid), disabled and read-only, all from the native input.
- The description, in this order: the prefix and suffix (read as
prefixLabelandsuffixLabelwhen given, "US dollars" for "$"), the supporting text, the error message, and the character counter, read as "Character count: 12 of 80" (labels.characterCount). - When the field is invalid the error message is shown in place of the supporting text, which stays in the description as visually hidden text. The error message has the
alertrole, so it is announced as it appears. - While invalid, and without a
trailingIcon, the field shows an error icon with theimgrole, named "Error" (labels.error).errorIconreplaces it, andfalseremoves it. - Leading icons are hidden from assistive tech (
aria-hidden). AtrailingIconis not, so an icon button there keeps its name. - With
supportingTextOnFocus, the supporting text only shows while the field has focus, but screen readers always get it. - The attributes that describe the input go to it, not to the field's container:
aria-controls,aria-expanded,aria-haspopup,aria-autocompleteandaria-activedescendantfor a field that opens its own suggestions, anaria-invalidoraria-requireda form library sets,aria-multilineandaria-placeholder, and the description attributes (aria-description,aria-roledescriptionand the braille labels).
Focus
- A disabled field can't be focused. A read-only field can, so its value can be selected and copied.
- Pressing anywhere in the container, except on an icon button or another control, focuses the input.
- Focus is shown by the field itself, as M3 draws it: the filled field's indicator line and the outlined field's border thicken to 2px and take the focus colour, along with the label. There is no separate focus ring.
Touch target
The container is at least 56px tall and spans the field, and leading and trailing icons sit in 48 × 48px boxes, so the field meets the 48px minimum.
Motion
Under reduced motion the label floats and settles at once, and the border and indicator change thickness at once; colours still fade.
What you need to do
- Give every field a visible
label. Usearia-labelonly where the purpose is clear without one, such as a search field with a search icon. - Pass an
errorMessagethat says how to fix the problem ("Enter an email address like name@example.com"), not just that it is wrong. - Say "Read-only" in the supporting text of a
readOnlyfield, since it looks like an editable one. - Set
type,inputModeandautoCompleteto match the data, so the right keyboard and autofill appear. - Name an icon button you pass as
trailingIconwith its ownaria-label.