# @salmonui/chat/text-suggest API reference

> 9 exported symbols of @salmonui/chat/text-suggest: 1 function, 5 interfaces and 3 types.

Canonical: https://salmonui.dev/docs/reference/chat/text-suggest

```ts
import { … } from '@salmonui/chat/text-suggest';
```

## Functions

### useTextSuggest

Kind: function

Page: https://salmonui.dev/docs/reference/chat/text-suggest/useTextSuggest

```ts
function useTextSuggest(options: TextSuggestOptions): TextSuggest;
```

Attaches inline suggestions to the `<textarea>` that receives `ref`. Options
are read when events happen, so `suggest` and the callbacks may be inline
functions.

## Interfaces

### BeforeSuggestionShowEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/text-suggest/BeforeSuggestionShowEvent

```ts
interface BeforeSuggestionShowEvent {
    readonly text: string;
    readonly defaultPrevented: boolean;
    preventDefault(): void;
}
```

Cancellable event fired before a suggestion shows.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `text` | `readonly text: string;` |  |  |
| `defaultPrevented` | `readonly defaultPrevented: boolean;` |  |  |
| `preventDefault` | `preventDefault(): void;` |  |  |

### SuggestContext

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/text-suggest/SuggestContext

```ts
interface SuggestContext {
    readonly value: string;
    readonly textBeforeCaret: string;
    readonly textAfterCaret: string;
}
```

What the application's `suggest` function receives.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: string;` |  |  |
| `textBeforeCaret` | `readonly textBeforeCaret: string;` |  |  |
| `textAfterCaret` | `readonly textAfterCaret: string;` |  |  |

### SuggestLocaleText

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/text-suggest/SuggestLocaleText

```ts
interface SuggestLocaleText {
    readonly acceptHint?: string | undefined;
}
```

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `acceptHint` | `readonly acceptHint?: string \| undefined;` | optional | Hint linked through `aria-describedby` while a suggestion is visible. Default "Tab to accept". |

### SuggestionEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/text-suggest/SuggestionEvent

```ts
interface SuggestionEvent {
    readonly text: string;
}
```

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `text` | `readonly text: string;` |  |  |

### TextSuggest

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/text-suggest/TextSuggest

```ts
interface TextSuggest {
    readonly ref: (textarea: HTMLTextAreaElement | null) => void;
}
```

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `ref` | `readonly ref: (textarea: HTMLTextAreaElement \| null) => void;` |  | Pass to the field: `<TextArea ref={suggest.ref} />` (a stable callback ref). |

## Types

### SuggestFunction

Kind: type

Page: https://salmonui.dev/docs/reference/chat/text-suggest/SuggestFunction

```ts
type SuggestFunction = (context: SuggestContext, init: {
    readonly signal: AbortSignal;
}) => Promise<string | null>;
```

### SuggestionDisplay

Kind: type

Page: https://salmonui.dev/docs/reference/chat/text-suggest/SuggestionDisplay

```ts
type SuggestionDisplay = 'inline' | 'popover' | 'auto';
```

`'auto'`: inline ghost text on fine pointers, a popover on coarse pointers, chosen by CSS.

### TextSuggestOptions

Kind: type

Page: https://salmonui.dev/docs/reference/chat/text-suggest/TextSuggestOptions

```ts
type TextSuggestOptions = SuggestOptions;
```

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `suggest` | `suggest: SuggestFunction;` | inherited |  |
| `suggestionDisplay` | `suggestionDisplay?: SuggestionDisplay;` | optional, inherited |  |
| `suggestDelay` | `suggestDelay?: number;` | optional, inherited | Idle time after the last keystroke before a request, in ms. Default 300. |
| `onBeforeSuggestionShow` | `onBeforeSuggestionShow?: ((event: BeforeSuggestionShowEvent) => void);` | optional, inherited |  |
| `onSuggestionShow` | `onSuggestionShow?: ((event: SuggestionEvent) => void);` | optional, inherited |  |
| `onSuggestionAccept` | `onSuggestionAccept?: ((event: SuggestionEvent) => void);` | optional, inherited |  |
| `localeText` | `localeText?: SuggestLocaleText;` | optional, inherited |  |
| `container` | `container?: HTMLElement;` | optional, inherited | Element that receives the overlay, hint and live region; it should be the textarea's positioned wrapper (`position: relative`). Default: the textarea's parent element. |
