Skip to content

Typeahead

@astryxdesign/core v0.7.1 · Typeahead

Typeahead Props ​

NameTypeDefaultDescription
modelValueT | nullnullSelected item. An item has at least id and label.
searchSourceSearchSource<T>RequiredStatic or async source. An empty query prefers bootstrap.
labelstringRequiredField label. Always available to assistive technology.
descriptionstring—Helper text under the label.
labelTooltipstring—Tooltip text on an info icon next to the label.
isLabelHiddenbooleanfalseHides the label visually while keeping it accessible. labelHidden is the older name; either one hides it.
containerClass / controlClassclass—Field shell and input box. A root class lands on the box, not the native input. An item action turns the menu into two columns and does not select the item.
startIconComponent—Icon at the start of the input. An icon slot replaces it.
placeholderstringSearch… / 搜索…Placeholder. English unless a locale is provided.
debounceMsnumber150Wait after typing before searching. Use 0 for local data.
minQueryLengthnumber1Shortest query that gets searched, counted in visible characters. Below it nothing is searched and the menu stays closed, so a query nobody searched never reports "no results". An empty query is not "too short": it still bootstraps.
hasEntriesOnFocusbooleanfalseShow bootstrap results on focus before the user types.
showOnFocusbooleanfalseLegacy name for hasEntriesOnFocus. Either one turns it on.
hasAutoFocusbooleanfalseFocus the input on mount.
maxMenuItemsnumber10Maximum rows in the menu.
hasClearbooleantrueShow a clear button that deselects the current value.
clearablebooleantrueLegacy name for hasClear. Turning either one off removes the button.
emptySearchTextstring | null'No results found' / '未找到结果'Text shown when the query matched nothing. null means "not given" and falls through to the default; an empty string renders nothing. For rich content use the empty slot.
emptyTextstring | null—Legacy name for emptySearchText.
disabledbooleanfalseDisable the field.
disabledMessagestring—Explains why the field is disabled. With disabled, the control stays focusable through aria-disabled and readonly instead of the native disabled, and the message shows as a tooltip on hover or keyboard focus.
disabledReasonstring—Legacy name for disabledMessage.
status'default' | 'success' | 'warning' | 'error''default'Status style.
statusMessagestring—Status text under the field.
size'sm' | 'md' | 'lg''md'Input and token size.
requiredbooleanfalseMarks the field as required.
optionalbooleanfalseShows an optional indicator on the label.
namestring—Form field name. Submits the selected id.
widthnumber | string—Width of the whole field (number = pixels, string used as-is).

Typeahead Emits ​

NameParametersDescription
update:modelValuevalue: T | nullEmitted when the selection is set or cleared.
changevalue: T | nullEmitted when the selection is set or cleared.
changeQueryquery: stringEmitted when the query text changes.
searchquery: stringLegacy name for changeQuery. Both fire.
openChangeisOpen: booleanEmitted when the menu opens or closes.

Typeahead Slots ​

NameParametersDescription
icon—Icon at the start of the input.
item{ item, isActive, isSelected }Custom menu row. Replaces the default TypeaheadItem.
empty—Custom empty state.

createStaticSource ​

NameTypeDescription
itemsT[]Local items.
keywords(item: T) => string[]Extra words included in the substring match.

Grouping results ​

Put a group name on item.auxiliaryData.group. Rows that share a name are rendered as one role="group" block with a visible heading, in the order the groups first appear. Rows without a group stay at their own position.

ts
const items = [
  { id: 'apple', label: 'Apple', auxiliaryData: { group: 'Fruit' } },
  { id: 'carrot', label: 'Carrot', auxiliaryData: { group: 'Vegetable' } },
]

BaseTypeahead ​

No field label, description, or validation message. Use it where the surrounding surface already has a title, such as a command palette. label here is the input's accessible name; omit it when an outside <label for> already names the input. The default menu row is TypeaheadItem, and the item slot replaces it.

NameTypeDefaultDescription
modelValueT | nullnullSelected item.
searchSourceSearchSource<T>RequiredStatic or async source.
labelstring—Accessible name of the input.
inputIdstringGeneratedId of the input, so an outside label can point at it.
describedBystring—Ids of the description and status the caller already computed.
ariaDescribedBystring—Input-specific alias for aria-describedby. Takes precedence over the native attribute.
ariaLabelledBystring—Input-specific alias for aria-labelledby. Takes precedence over the native attribute.
anchorRefHTMLElement | null—Element the dropdown hangs from and measures itself against. Defaults to the input's own wrapper.
inputTabIndexnumber—Tab order of the input. Defaults to -1 while the selected token covers the input, so the invisible input is not a tab stop.
isFocusableDisabledbooleanfalseKeep a disabled input focusable through aria-disabled and readonly so a caller-owned disabled reason stays discoverable. Text entry stays blocked.
hasAutoFocusbooleanfalseFocus the input on mount.
hasEntriesOnFocusbooleanfalseShow bootstrap results on focus before the user types.
showOnFocusbooleanfalseLegacy name for hasEntriesOnFocus. Either one turns it on.
minQueryLengthnumber1Shortest query that gets searched, counted in visible characters. Below it nothing is searched and the menu stays closed.
menuWidthnumber—Requested dropdown width in pixels. Never narrower than the anchor, and clamped to the viewport.
maxMenuItemsnumber10Maximum rows in the menu.
emptySearchTextstring | null'No results found' / '未找到结果'Text shown when the query matched nothing. null falls through to the default; an empty string renders nothing.
emptyTextstring | null—Legacy name for emptySearchText.
placeholderstringSearch…Input placeholder.
disabledbooleanfalseDisable the input.
disabledReasonstring—Why the input is disabled. Shown as a tooltip and announced as the description while the input stays focusable.
status'default' | 'success' | 'warning' | 'error''default'Border color of the control.
size'sm' | 'md' | 'lg''md'Input and token size.
clearablebooleantrueShow a clear button.
debounceMsnumber150Wait after typing before searching. Use 0 for local data.
requiredbooleanfalseMarks the input as required.
namestring—Form field name. Submits the selected id.
NameParametersDescription
update:modelValuevalue: T | nullEmitted when the selection is set or cleared.
changevalue: T | nullEmitted when the selection is set or cleared.
changeQueryquery: stringEmitted when the query text changes.
searchquery: stringLegacy name for changeQuery. Both fire.
openChangeisOpen: booleanEmitted when the menu opens or closes.

Native attributes and listeners that are not listed above land on the input element, so @keydown, @focus, @blur and aria-* work as they would on a plain <input>. A keydown listener runs before the internal keyboard navigation; call event.preventDefault() to skip it.

TypeaheadItem ​

NameTypeDefaultDescription
itemSearchableItemRequiredThe search result this row shows.
descriptionstring—Overrides the item's own description.
groupstring—Accepted for API parity; the row itself draws no heading. Grouping is done by the menu from item.auxiliaryData.group.
isDisabledbooleanfalsePaints the row as unavailable.
icon (slot)——Icon or avatar shown before the label.