EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
Typeahead·component·@astryxdesign/core

Typeahead Item

Default dropdown item renderer for typeahead results. Shows label with optional icon, description, and avatar. Exported for use in custom renderItem implementations.

Open in Playground @astryxdesign/core/Typeahead

Showcases and examples

2 documented examples

Typeahead Item

Typeahead with custom item rendering using TypeaheadItem for avatars and descriptions.

Preview loads on approachPreview loads on approach
Exact source · typeahead-item-showcase
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {useState} from 'react';
import {Typeahead, TypeaheadItem} from '@astryxdesign/core/Typeahead';
import type {SearchableItem, SearchSource} from '@astryxdesign/core/Typeahead';
import {Avatar} from '@astryxdesign/core/Avatar';
import {Center} from '@astryxdesign/core/Center';

interface PersonItem extends SearchableItem {
  auxiliaryData: {role: string};
}

const people: PersonItem[] = [
  {id: '1', label: 'Alice Johnson', auxiliaryData: {role: 'Engineer'}},
  {id: '2', label: 'Bob Smith', auxiliaryData: {role: 'Designer'}},
  {id: '3', label: 'Charlie Brown', auxiliaryData: {role: 'Product Manager'}},
  {id: '4', label: 'Diana Prince', auxiliaryData: {role: 'Data Scientist'}},
  {id: '5', label: 'Eve Davis', auxiliaryData: {role: 'QA Engineer'}},
];

const peopleSource: SearchSource<PersonItem> = {
  search: (query: string) =>
    people.filter(p => p.label.toLowerCase().includes(query.toLowerCase())),
  bootstrap: () => people.slice(0, 4),
};

export default function TypeaheadItemShowcase() {
  const [value, setValue] = useState<PersonItem | null>(null);

  return (
    <Center width={320}>
      <Typeahead
        label="Assignee"
        placeholder="Search people..."
        searchSource={peopleSource}
        value={value}
        onChange={setValue}
        renderItem={(item: PersonItem) => (
          <TypeaheadItem
            item={item}
            icon={<Avatar name={item.label} size="md" />}
            description={item.auxiliaryData.role}
          />
        )}
      />
    </Center>
  );
}

Usage

Default dropdown item renderer for typeahead results. Shows label with optional icon, description, and avatar. Exported for use in custom renderItem implementations.

Typed props

PropType and behavior
itemSearchableItem · required
The search result item to render.
iconReactNode
Icon or avatar to display before the label.
Slot: Icon
descriptionstring
Description text displayed below the label.
isDisabledboolean · default false
Whether this item is visually disabled.
groupstring
Group label for grouping items visually.