# Suggest Field

AI autocomplete textarea with inline ghost text: a suggestion follows the typing, Tab accepts and Esc dismisses, and a Suggest button turns into Accept beside Dismiss. The caller supplies the suggestion.

Component · Chat · https://01orbital.dev/docs/components/suggest-field

## Installation

```bash
npx shadcn@latest add @01orbital/suggest-field
```

## Usage

```tsx
"use client"

import * as React from "react"

import { SuggestField } from "@/components/chat/suggest-field"

const GHOST = "can be swapped for any backend that streams SSE."

export default function SuggestFieldDemo() {
  const [value, setValue] = React.useState(
    "The registry provides the conversation surface as primitives, so the transport"
  )
  const [suggestion, setSuggestion] = React.useState("")
  const [loading, setLoading] = React.useState(false)
  const timer = React.useRef<number | null>(null)

  React.useEffect(
    () => () => {
      if (timer.current) window.clearTimeout(timer.current)
    },
    []
  )

  return (
    <div className="max-w-xl">
      <SuggestField
        value={value}
        onValueChange={setValue}
        onRequest={() => {
          setLoading(true)
          timer.current = window.setTimeout(() => {
            setSuggestion(GHOST)
            setLoading(false)
          }, 700)
        }}
        onDismiss={() => setSuggestion("")}
        suggestion={suggestion}
        loading={loading}
        placeholder="Start a sentence…"
      />
    </div>
  )
}
```

This example installs with everything it uses:

```bash
npx shadcn@latest add @01orbital/suggest-field-demo
```

## API reference

A text box that offers an AI continuation as faint text after what the person typed. Tab takes the suggestion, Esc drops it, and a button asks for one.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` |  | The text in the field. |
| `onValueChange` | `(value: string) => void` |  | Called on every change, including when a suggestion is taken. |
| `onRequest` | `() => void` |  | Called when the person asks for a suggestion with the button. |
| `onDismiss` | `() => void` |  | Called when a suggestion is taken or dropped, so you can clear it. |
| `suggestion?` | `string` | `""` | The suggested continuation, shown as faint text after the cursor. |
| `loading?` | `boolean` | `false` | True while a suggestion is being fetched. |
| `label?` | `string` | `"Text to complete"` | The field's accessible name. |
| `placeholder?` | `string` |  | Hint text for the empty field. It is hidden while a suggestion shows. There is none by default. |
| `rows?` | `number` | `5` | The field's height in lines of text. It keeps that height and scrolls instead of growing. Defaults to 5. |
| `className?` | `string` |  | Extra classes for the outer `div` around the field and its button row. |

## Dependencies

Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:

- [Button](https://01orbital.dev/docs/components/button)
- [Kbd](https://01orbital.dev/docs/components/kbd)
- [Textarea](https://01orbital.dev/docs/components/textarea)

The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.

npm: `cn`
