Beta FeatureThis feature is currently in beta, and needs to be imported from
@servicetitan/anvil2/beta.While we hope to minimize breaking changes, they may occur due to feedback we receive or other improvements. These will always be documented in the changelog and communicated in Slack.Please reach out in the #ask-designsystem channel with any questions or feedback!- Implementation
- TypeaheadTextField Props
Overview
TypeaheadTextField extends TextField with a suggestion menu that opens as the user types. Provide a loadOptions callback that returns the matching options for the current input value; it may return an array synchronously or a Promise for remote data. Unlike SelectField, the input accepts any free-form text — suggestions assist entry rather than constrain it to a fixed set.Reach for TypeaheadTextField over SelectField when a suggestion needs to display more than what belongs in the field. On selection, only the option’s label is written to the input, while the full option — including its structured value — is delivered to onSelectOption. This keeps supporting detail shown in the menu out of the field, while letting that detail populate the rest of the form. For example, an address typeahead can render full formatted addresses in the menu, write only the street line to the field, and use onSelectOption to fill the city, state, and postal code fields.Because the field also accepts free-form text, set isHighlighted whenever its value comes from a selected suggestion so users can tell a confirmed choice apart from typed text. Track this alongside the value: set it true in onSelectOption and false in onChange. See Highlighting a selected value.Options are objects of type TypeaheadTextFieldOption:Basic Usage
Common Examples
Synchronous options
Return an array fromloadOptions to filter a static list on the client. Set debounceMs={0} when there is no network cost to debounce against.Asynchronous options
Return aPromise to load suggestions from a remote source. A spinner shows while the request is in flight, and the field discards stale responses so the menu always reflects the latest input. Tune debounceMs to limit how often loadOptions is called.Controlled
The input value is uncontrolled by default. Passvalue and onChange to control it, and use onSelectOption to react when a suggestion is chosen.Highlighting a selected value
SetisHighlighted while the field’s value comes from a selected suggestion to mark it as a confirmed choice. Set it true in onSelectOption and clear it in onChange, so the highlight turns off the moment the user edits the value away from the suggestion. This is the recommended pattern whenever selecting a suggestion carries meaning beyond the text in the field.Open on empty focus
By default the menu opens only when the input holds a value. PassopenOnEmptyFocus to also open it on focus or click while the input is empty, which suits “show all” menus that don’t require pre-typing.Custom option rendering
PassrenderOption to render richer content for each suggestion row. The returned node replaces the default label text; loadOptions still drives which options appear.React Accessibility
Provide alabel so screen readers announce the field’s purpose. The component wires up the combobox and listbox ARIA roles, expanded state, and the relationship between the input and the suggestion menu.For more guidance on form field labels and context, see input field context association best practices.