Skip to main content

Common Examples

Import TextField from @servicetitan/anvil2 and pass a string label. The label is associated with the input. Unlisted attributes such as name are forwarded to the input, so the field participates in a native form submit.

Managing text field state

TextField keeps the input controlled internally. Omit value for an uncontrolled field, and pass defaultValue for an initial value. Pass value with onChange to control it. Do not pass value and defaultValue together.

Uncontrolled text fields

Give the field a name and submit it with a Button set to type="submit". Read the value from the form event, as in the example above.

Controlled text fields

Store the string in React state and pass it back through value. onChange receives the input’s change event.

Show character counter

Use the maxLength and showCounter props to display a character counter below the text field.

Markdown in labels

The label prop supports inline markdown: bold (**text**), italic (*text*), bold and italic (***text***), highlight (==text==), and code (`text`).

Hide the label

Use hideLabel to visually hide the label. The label string is converted to an aria-label on the input so it remains accessible to screen readers — any inline markdown is stripped to plain text.

React Accessibility

TextField renders a native input and a label whose htmlFor matches the input id. When id is omitted, one is generated.
  • Pass a string label. That string is the accessible name. Omitting label is deprecated. On that deprecated path, placeholder is copied to aria-label when aria-label is also omitted.
  • hideLabel removes the visible label and sets aria-label from the label string, with inline markdown stripped. An explicit aria-label is ignored in that case.
  • When the label is visible, an explicit aria-label replaces the label as the accessible name. Omit aria-label so the visible label is announced.
  • prefix and suffix are aria-hidden. Put that meaning in label or hint.
  • required sets the input’s required attribute and adds a visual asterisk plus screen-reader text “Required” on the label.
  • A truthy error sets aria-invalid. Error text is announced with aria-live="assertive". Warning text is announced with aria-live="polite". errorAriaLive is ignored.
  • Hint, description, error, and warning are grouped in one region referenced by aria-describedby. Hint stays in that region when an error or warning is also shown.
  • moreInfo adds a button labeled “More information” after the label. The tooltip content is also exposed through aria-describedby.
  • The character counter is aria-hidden. While the user is typing and maxLength is set, a live region announces the remaining characters, or that the maximum has been reached.
For more guidance on form field labels and context, see input field context association best practices.
Last modified on October 5, 2026