Skip to main content

Common Examples

import { TextField } from "@servicetitan/anvil2";

function ExampleComponent() {
  return (
    <TextField
      label="Label"
      placeholder="Placeholder"
      hint="Hint text"
      moreInfo="More info"
      required
      error={false}
    />
  );
}
The TextField component can be used in the same way that you would use a pairing of HTML input and label elements.

Managing text field state

There are many ways to handle form element values and state. The Anvil2 TextField component is very flexible and can be implemented as part of a form, using React ref, or by manually controlling state.

Text fields in an uncontrolled form

Use a TextField in the same manner as an HTML input element with an associated label. The Anvil2 Button can be used with type="submit" to submit all of the form input values.

Controlled text fields

To manually control the state of a text field, use the value and onChange props along with a React state (or similar state management tool).

Show character counter

Use the maxLength and showCounter props to display a character counter below the text field.
Last modified on January 23, 2026