Astryx

Astryx Typeahead Item

Component

About

Default dropdown item renderer for typeahead results. Shows label with optional icon, description, and avatar. Exported for use in custom renderItem implementations. Astryx by Meta. Source: https://astryx.atmeta.com/components/TypeaheadItem

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Astryx Typeahead Item to your project and fits it to your theme.

Code

How Astryx Typeahead Item is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

'use client';

/* Copyright (c) 2026 Meta Platforms, Inc. See the MIT notice in astryx-typeahead-item.tsx. */

import '@/components/ui/astryx-typeahead-item-utils/astryx-preview.css';
import '@astryxdesign/theme-neutral/fonts.css';
import {useSyncExternalStore} from 'react';
import {Theme} from '@astryxdesign/core/theme';
import {neutralTheme} from '@astryxdesign/theme-neutral/built';

import {useState} from 'react';
import {Typeahead, TypeaheadItem} from '@/components/ui/astryx-typeahead-item';
import type {SearchableItem, SearchSource} from '@/components/ui/astryx-typeahead-item';
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),
};

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

  return (
    <Center width="100%">
      <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>
  );
}

function readPreviewMode() {
  const {classList} = document.documentElement;
  return classList.contains('dark') ? 'dark' : 'light';
}

function subscribeToPreviewMode(callback: () => void) {
  const observer = new MutationObserver(callback);
  observer.observe(document.documentElement, {attributes: true, attributeFilter: ['class']});
  return () => observer.disconnect();
}

export default function Demo() {
  const mode = useSyncExternalStore(subscribeToPreviewMode, readPreviewMode, () => 'light' as const);
  return (
    <Theme theme={neutralTheme} mode={mode}>
      <div className="astryx-demo">
        <div className="astryx-demo-content" data-centered style={{maxWidth: 320}}>
          <OfficialSample />
        </div>
      </div>
    </Theme>
  );
}

Dependencies

More by Astryx

View all
  • Astryx Banner

    Astryx Banner

    61
  • Astryx Avatar

    Astryx Avatar

    34
  • Astryx Aspect Ratio

    Astryx Aspect Ratio

    32
  • Astryx Badge

    Astryx Badge

    30
  • Astryx Button Group

    Astryx Button Group

    29
  • Astryx Chat Composer Drawer

    Astryx Chat Composer Drawer

    27
  • Astryx Toggle Button

    Astryx Toggle Button

    17
  • Astryx Chat Tokenized Text

    Astryx Chat Tokenized Text

    12