Astryx

Astryx Base Typeahead

Forms 3

About

A composable Astryx combobox engine with search, keyboard navigation, custom results, and anchored dropdown positioning.

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

Code

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

Usage.tsx

"use client"

import { useRef, useState } from "react"
import BaseTypeahead, {
  createStaticSource,
  type SearchableItem,
} from "@/components/ui/astryx-base-typeahead"
import { Icon } from "@astryxdesign/core/Icon"
import { HStack, VStack } from "@astryxdesign/core/Layout"
import { Text } from "@astryxdesign/core/Text"
import {
  borderVars,
  colorVars,
  focusVars,
  radiusVars,
  spacingVars,
} from "@astryxdesign/core/theme/tokens.stylex"
import { MagnifyingGlassIcon } from "@heroicons/react/24/outline"

const frameworks: SearchableItem[] = [
  { id: "react", label: "React" },
  { id: "vue", label: "Vue" },
  { id: "angular", label: "Angular" },
  { id: "svelte", label: "Svelte" },
  { id: "solid", label: "SolidJS" },
  { id: "remix", label: "Remix" },
  { id: "next", label: "Next.js" },
  { id: "nuxt", label: "Nuxt" },
]

const source = createStaticSource(frameworks)

export default function BaseTypeaheadDemo() {
  const [value, setValue] = useState<SearchableItem | null>(null)
  const [isFocusVisible, setIsFocusVisible] = useState(false)
  const wrapperRef = useRef<HTMLDivElement>(null)

  return (
    <VStack
      data-astryx-theme="neutral"
      data-theme="light"
      gap={3}
      style={{ colorScheme: "light", width: "100%", maxWidth: 360 }}
    >
      <HStack
        ref={wrapperRef}
        gap={2}
        vAlign="center"
        onFocusCapture={(event) => setIsFocusVisible(event.target.matches(":focus-visible"))}
        onBlurCapture={() => setIsFocusVisible(false)}
        style={{
          backgroundColor: colorVars["--color-background-surface"],
          borderColor: colorVars["--color-border"],
          borderRadius: radiusVars["--radius-element"],
          borderStyle: "solid",
          borderWidth: borderVars["--border-width"],
          paddingBlock: spacingVars["--spacing-1-5"],
          paddingInline: spacingVars["--spacing-2"],
          outlineColor: isFocusVisible ? focusVars["--focus-outline-color"] : "transparent",
          outlineOffset: focusVars["--focus-outline-offset"],
          outlineStyle: "solid",
          outlineWidth: isFocusVisible ? focusVars["--focus-outline-width"] : 0,
        }}
      >
        <Icon icon={MagnifyingGlassIcon} size="sm" color="secondary" />
        <BaseTypeahead
          aria-label="Search frameworks"
          searchSource={source}
          value={value}
          onChange={setValue}
          anchorRef={wrapperRef}
          placeholder="Search frameworks…"
          hasEntriesOnFocus
          debounceMs={0}
        />
      </HStack>
      <Text type="supporting" color="secondary">
        {value != null ? `Selected: ${value.label}` : "No selection"}
      </Text>
    </VStack>
  )
}

Dependencies

More by Astryx

View all
  • Astryx Banner

    Astryx Banner

    61
  • Astryx Avatar

    Astryx Avatar

    32
  • Astryx Aspect Ratio

    Astryx Aspect Ratio

    32
  • Astryx Badge

    Astryx Badge

    29
  • Astryx Button Group

    Astryx Button Group

    28
  • Astryx Chat Composer Drawer

    Astryx Chat Composer Drawer

    25
  • Astryx Toggle Button

    Astryx Toggle Button

    17
  • Astryx Chat Tokenized Text

    Astryx Chat Tokenized Text

    9

More in Forms

View all
  • Premium Auth

    Premium Auth

    593
  • Contact Form

    Contact Form

    28
  • Form

    Form

    4
  • Login 1

    Login 1

    70
  • Book A Demo 1

    Book A Demo 1

    94
  • Contact Card

    Contact Card

    1.1K
  • HeroUI Field Error

    HeroUI Field Error

    13
  • Form [react-aria-components]

    Form [react-aria-components]

    19