- Implementation
- TextField Props
Common Examples
ImportTextField 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 aname 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 throughvalue. onChange receives the input’s change event.Show character counter
Use themaxLength and showCounter props to display a character counter below the text field.Markdown in labels
Thelabel prop supports inline markdown: bold (**text**), italic (*text*), bold and italic (***text***), highlight (==text==), and code (`text`).Hide the label
UsehideLabel 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. Omittinglabelis deprecated. On that deprecated path,placeholderis copied toaria-labelwhenaria-labelis also omitted. hideLabelremoves the visible label and setsaria-labelfrom the label string, with inline markdown stripped. An explicitaria-labelis ignored in that case.- When the label is visible, an explicit
aria-labelreplaces the label as the accessible name. Omitaria-labelso the visible label is announced. prefixandsuffixarearia-hidden. Put that meaning inlabelorhint.requiredsets the input’srequiredattribute and adds a visual asterisk plus screen-reader text “Required” on the label.- A truthy
errorsetsaria-invalid. Error text is announced witharia-live="assertive". Warning text is announced witharia-live="polite".errorAriaLiveis 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. moreInfoadds a button labeled “More information” after the label. The tooltip content is also exposed througharia-describedby.- The character counter is
aria-hidden. While the user is typing andmaxLengthis set, a live region announces the remaining characters, or that the maximum has been reached.