TextField
TextField is a single-line or multiline text input with optional label, description, and error message. Use it in forms for short answers (email, search, name) or longer content (comments). It supports optional leading and trailing text adornments (e.g. currency or units).
Features
- Label, description, error: Optional label, helper text, and error message with proper accessibility
- Adornments: Optional
leadingTextandtrailingTextfor fixed text before or after the input (e.g.$,.00,px) - Controlled or uncontrolled: Use
valueandonChangefor controlled state, ordefaultValuefor uncontrolled - Multiline: Set
multilineto render a textarea instead of a single-line input - Validation states: Use
isInvalidwitherrorMessageandisDisabledfor validation and disabled state - React Aria integration: Built on React Aria TextField for accessibility and behavior
Installation
npm install --save @godaddy/antaresProps
The TextField component accepts the following props:
description?string | undefined—Helper text shown below the frame.
defaultValue?string | undefined—Default value (uncontrolled).
errorMessage?string | undefined—Error message shown when invalid. Use with isInvalid.
isDisabled?boolean | undefined—Whether the input is disabled.
isInvalid?boolean | undefined—Whether the value is invalid. Use with errorMessage for validation.
isRequired?boolean | undefined—Whether user input is required before form submission.
label?string | undefined—Label text shown above the frame.
leadingText?string | undefined—Text rendered before the input (leading adornment).
multiline?boolean | undefined—When true, renders a textarea instead of a single-line input.
name?string | undefined—Name of the input element, used when submitting a form.
onChange?((value: string) => void) | undefined—Handler called when the value changes.
placeholder?string | undefined—Placeholder text when the input value is empty.
trailingText?string | undefined—Text rendered after the input (trailing adornment).
value?string | undefined—Current value (controlled).
validationBehavior?"native" | "aria" | undefined'native'Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
enterKeyHint?"search" | "enter" | "done" | "go" | "next" | "previous" | "send" | undefined—An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint).
isReadOnly?boolean | undefined—Whether the input can be selected but not changed by the user.
validate?((value: string) => ValidationError | true | null | undefined) | undefined—A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if `validationBehavior="native"`. For realtime validation, use the `isInvalid` prop instead.
autoFocus?boolean | undefined—Whether the element should receive focus on render.
onFocus?((e: React.FocusEvent<HTMLInputElement, Element>) => void) | undefined—Handler that is called when the element receives focus.
onBlur?((e: React.FocusEvent<HTMLInputElement, Element>) => void) | undefined—Handler that is called when the element loses focus.
onFocusChange?((isFocused: boolean) => void) | undefined—Handler that is called when the element's focus status changes.
onKeyDown?((e: KeyboardEvent) => void) | undefined—Handler that is called when a key is pressed.
onKeyUp?((e: KeyboardEvent) => void) | undefined—Handler that is called when a key is released.
excludeFromTabOrder?boolean | undefined—Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
id?string | undefined—The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
autoComplete?string | undefined—Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).
maxLength?number | undefined—The maximum number of characters supported by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength).
minLength?number | undefined—The minimum number of characters required by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength).
pattern?string | undefined—Regex pattern that the value of the input must match to be valid. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefpattern).
type?"search" | "text" | "url" | "tel" | "email" | "password" | (string & {}) | undefined'text'The type of input to render. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype).
inputMode?"search" | "text" | "none" | "url" | "tel" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents. See [MDN](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute).
autoCorrect?string | undefined—An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete).
spellCheck?string | undefined—An enumerated attribute that defines whether the element may be checked for spelling errors. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck).
form?string | undefined—The `<form>` element to associate the input with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).
style?StyleOrFunction<TextFieldRenderProps> | undefined—The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state.
className?ClassNameOrFunction<TextFieldRenderProps> | undefined'react-aria-TextField'The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.
render?DOMRenderFunction<"div", TextFieldRenderProps> | undefined—Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements: - You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`). - Only a single root DOM element can be rendered (no fragments). - You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
slot?string | null | undefined—A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent.
Examples
Basic
Minimal usage with label and placeholder.
import { TextField, type TextFieldProps } from '@godaddy/antares';export function TextFieldBasic(props: TextFieldProps) { return <TextField label="Name" placeholder="Enter your name" {...props} />;}Controlled
Use value and onChange for controlled state.
import { useState } from 'react';import { Text, TextField } from '@godaddy/antares';export function TextFieldControlledExample() { const [value, setValue] = useState(''); return ( <> <TextField label="Email" placeholder="you@example.com" value={value} onChange={setValue} /> <Text> <strong>Value:</strong> {value || '(empty)'} </Text> </> );}Invalid
Use isInvalid with errorMessage for validation feedback.
import { TextField } from '@godaddy/antares';export function TextFieldInvalidExample() { return ( <TextField label="Email" placeholder="you@example.com" errorMessage="Please enter a valid email address" isInvalid isRequired /> );}Disabled
Use isDisabled to prevent input.
import { TextField } from '@godaddy/antares';export function TextFieldDisabledExample() { return <TextField label="Name" placeholder="Enter your name" defaultValue="Disabled value" isDisabled />;}Adornments
Use leadingText and trailingText for fixed text before and after the input (e.g. currency).
import { TextField } from '@godaddy/antares';export function TextFieldAdornmentsExample() { return ( <TextField description="Use leadingText and trailingText to show fixed text before and after the input (e.g. currency)." label="Amount" leadingText="$" placeholder="0.00" trailingText=".00" /> );}Multiline
Use multiline to render a textarea.
import { TextField, type TextFieldProps } from '@godaddy/antares';export function TextFieldMultilineExample(props: TextFieldProps) { return <TextField label="Comment" placeholder="Enter your comment" multiline {...props} />;}