# Prompt Suggestions

> Offer prompt starters a person can send with one click, as chips, a scrolling row, or a list.

Source: https://www.honestui.com/docs/ai/prompt-suggestions

```tsx
"use client"

import * as React from "react"
import {
  ChartLine as ChartLineIcon,
  FileText as FileTextIcon,
  Mail as MailIcon,
  Search as SearchIcon,
} from "honestui/icons"

import { PromptSuggestions, type PromptSuggestion } from "@/components/ai/prompt-suggestions"

// Sample prompt starters.
const sampleSuggestions: PromptSuggestion[] = [
  { id: "late", label: "Find late invoices", prompt: "Which invoices are more than 30 days late?", icon: <SearchIcon /> },
  { id: "trend", label: "Chart this month's revenue", icon: <ChartLineIcon /> },
  { id: "summary", label: "Summarize the Q3 report", icon: <FileTextIcon /> },
  { id: "email", label: "Draft a payment reminder", icon: <MailIcon /> },
]

/** Nothing is sent here. It shows the prompt your `onSelect` receives. */
export function PromptSuggestionsDemo() {
  const [chosen, setChosen] = React.useState<string | null>(null)

  return (
    <div className="flex w-full max-w-lg min-w-0 flex-col gap-[var(--hui-space-5)]">
      <PromptSuggestions suggestions={sampleSuggestions} onSelect={(suggestion) => setChosen(suggestion.prompt)} />
      <p
        aria-live="polite"
        className="m-0 min-h-5 px-[var(--hui-space-2)] text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] [line-height:var(--hui-line-height-small)]"
      >
        {chosen && <>Sent: {chosen}</>}
      </p>
    </div>
  )
}

```

## Overview [#overview]

Prompt Suggestions shows a few things a person could ask next. Choosing one calls `onSelect` with its prompt. Sending it, or putting it in the composer first, is your application's work.

It renders the suggestions you pass. Use it under a reply, above a composer, or inside [Chat Welcome](/docs/ai/chat-welcome) on a new conversation.

Use [Streaming Text](/docs/ai/streaming-text)'s follow-ups for prompts that continue one reply, and Prompt Suggestions for starters that stand on their own.

## Anatomy [#anatomy]

<Anatomy title="PromptSuggestions">
  <AnatomyItem name="Suggestion" description="A button with an optional icon and a short label" />
</Anatomy>

## Behavior [#behavior]

### Prompt and label [#prompt-and-label]

The chip shows `label`. When the prompt to send is longer, pass it as `prompt`; `onSelect` receives the suggestion with `prompt` filled in from the label when you leave it out.

### Layouts [#layouts]

`wrap` flows the chips onto more lines. `scroll` keeps them on one line that scrolls sideways, for a narrow composer. `list` stacks them as full-width rows in one block, for longer prompts.

### Disabled [#disabled]

`disabled` turns every suggestion off, such as while a reply is streaming.

## Accessibility [#accessibility]

The suggestions are a list of buttons named by their labels, and the list is named "Suggested prompts". They take one stop in the Tab order; the arrow keys move between them. Icons are decorative.

| Key                                  | Action                                                                                 |
| ------------------------------------ | -------------------------------------------------------------------------------------- |
| <kbd>Tab</kbd>                       | Move into or out of the suggestions                                                    |
| <kbd>→</kbd> <kbd>←</kbd>            | Move to the next or previous suggestion (<kbd>↓</kbd> <kbd>↑</kbd> in the list layout) |
| <kbd>Home</kbd> <kbd>End</kbd>       | Move to the first or last suggestion                                                   |
| <kbd>Enter</kbd> or <kbd>Space</kbd> | Choose the focused suggestion                                                          |

## Installation [#installation]


  

  
    <CliBlock commands="[&#x22;@honestai/prompt-suggestions&#x22;]" />
  

  
    
      
        Copy and paste this file into your project.
      

      ### components/ai/prompt-suggestions.tsx

```tsx
"use client"

import * as React from "react"

import { cn } from "@/lib/utils"

export type PromptSuggestion = {
  id: string
  /** The words on the chip. */
  label: string
  /** The prompt to send, when it is longer than the label. Defaults to the label. */
  prompt?: string
  /** A small decorative icon before the label. */
  icon?: React.ReactNode
}

export type PromptSuggestionsLabels = {
  /** Names the group for screen readers. */
  group: string
}

export const defaultPromptSuggestionsLabels: PromptSuggestionsLabels = {
  group: "Suggested prompts",
}

export type PromptSuggestionsProps = Omit<React.ComponentProps<"ul">, "children" | "onSelect"> & {
  suggestions: PromptSuggestion[]
  /** Called with the chosen suggestion. Its `prompt` falls back to its `label`. */
  onSelect: (suggestion: PromptSuggestion & { prompt: string }) => void
  /**
   * "wrap" lets the chips flow onto more lines. "scroll" keeps them on one
   * line that scrolls sideways. "list" stacks them as full-width rows.
   */
  layout?: "wrap" | "scroll" | "list"
  /** Turns every chip off, such as while a reply is streaming. */
  disabled?: boolean
  labels?: Partial<PromptSuggestionsLabels>
}

const regularText =
  "[font-size:var(--hui-font-size-regular)] [letter-spacing:var(--hui-letter-spacing-regular)] [line-height:var(--hui-line-height-regular)]"

/**
 * Prompt starters a person can send with one click. It renders the
 * suggestions you pass; Arrow keys move between them once one has focus.
 */
function PromptSuggestions({
  suggestions,
  onSelect,
  layout = "wrap",
  disabled = false,
  labels: labelsProp,
  className,
  onKeyDown,
  ...props
}: PromptSuggestionsProps) {
  const labels = { ...defaultPromptSuggestionsLabels, ...labelsProp }
  const isList = layout === "list"

  // One stop in the Tab order; the arrow keys move along the row.
  const [activeIndex, setActiveIndex] = React.useState(0)
  const buttonRefs = React.useRef<(HTMLButtonElement | null)[]>([])
  const tabIndexFor = Math.min(activeIndex, Math.max(suggestions.length - 1, 0))

  function moveFocus(next: number) {
    const count = suggestions.length
    if (count === 0) return
    const index = (next + count) % count
    setActiveIndex(index)
    const button = buttonRefs.current[index]
    button?.focus()
    button?.scrollIntoView?.({ block: "nearest", inline: "nearest" })
  }

  function handleKeyDown(event: React.KeyboardEvent<HTMLUListElement>) {
    onKeyDown?.(event)
    if (event.defaultPrevented) return
    const forward = isList ? "ArrowDown" : "ArrowRight"
    const backward = isList ? "ArrowUp" : "ArrowLeft"
    const keys: Record<string, () => void> = {
      [forward]: () => moveFocus(tabIndexFor + 1),
      [backward]: () => moveFocus(tabIndexFor - 1),
      Home: () => moveFocus(0),
      End: () => moveFocus(suggestions.length - 1),
    }
    const action = keys[event.key]
    if (!action) return
    event.preventDefault()
    action()
  }

  if (suggestions.length === 0) return null

  return (
    <ul
      role="list"
      aria-label={labels.group}
      data-slot="prompt-suggestions"
      data-layout={layout}
      onKeyDown={handleKeyDown}
      className={cn(
        "m-0 flex min-w-0 list-none p-0",
        layout === "wrap" && "flex-wrap gap-[var(--hui-space-3)]",
        // Room for the focus ring and the shadow inside the scroller.
        layout === "scroll" &&
          "-m-[var(--hui-space-2)] gap-[var(--hui-space-3)] overflow-x-auto p-[var(--hui-space-2)] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
        isList &&
          "flex-col overflow-hidden rounded-[var(--hui-radius-4)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-primary)] shadow-[var(--hui-shadow-feather)]",
        className
      )}
      {...props}
    >
      {suggestions.map((suggestion, index) => (
        <li
          key={suggestion.id}
          className={cn(
            "min-w-0",
            layout === "scroll" && "shrink-0",
            isList && "border-b-[0.5px] border-[var(--hui-color-border-base-primary)] last:border-b-0"
          )}
        >
          <button
            ref={(node) => {
              buttonRefs.current[index] = node
            }}
            type="button"
            data-slot="prompt-suggestion"
            disabled={disabled}
            tabIndex={index === tabIndexFor ? 0 : -1}
            onFocus={() => setActiveIndex(index)}
            onClick={() => onSelect({ ...suggestion, prompt: suggestion.prompt ?? suggestion.label })}
            className={cn(
              "group/suggestion flex min-w-0 cursor-pointer items-center gap-[var(--hui-space-3)] text-left text-[var(--hui-color-foreground-base-primary)] outline-none motion-safe:[transition:var(--hui-transition-interactive)] focus-visible:[outline:var(--hui-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50",
              regularText,
              isList
                ? "min-h-11 w-full rounded-none border-0 bg-transparent px-[var(--hui-space-5)] py-[var(--hui-space-3)] not-disabled:hover:bg-[var(--hui-color-background-base-primary-hover)] focus-visible:outline-offset-[var(--hui-focus-ring-offset-inset)]"
                : "min-h-9 max-w-full rounded-[var(--hui-radius-5)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-primary)] px-[var(--hui-space-5)] py-[var(--hui-space-2)] shadow-[var(--hui-shadow-feather)] not-disabled:hover:border-[var(--hui-color-border-base-secondary)] not-disabled:hover:bg-[var(--hui-color-background-base-primary-hover)] focus-visible:outline-offset-[var(--hui-focus-ring-offset-accent)]",
              suggestion.icon && !isList && "ps-[var(--hui-space-4)]"
            )}
          >
            {suggestion.icon && (
              <span
                aria-hidden="true"
                className="flex shrink-0 text-[var(--hui-color-foreground-base-tertiary)] group-hover/suggestion:text-[var(--hui-color-foreground-base-secondary)] [&_svg]:size-4"
              >
                {suggestion.icon}
              </span>
            )}
            <span className={cn("min-w-0", layout === "scroll" ? "whitespace-nowrap" : "break-words")}>
              {suggestion.label}
            </span>
          </button>
        </li>
      ))}
    </ul>
  )
}

export { PromptSuggestions }

```

      
        Update the import paths to match your project setup.
      
    
  


## Usage [#usage]

```tsx
import { PromptSuggestions } from "@/components/ai/prompt-suggestions"

<PromptSuggestions
  suggestions={[
    { id: "late", label: "Find late invoices", prompt: "Which invoices are more than 30 days late?" },
    { id: "trend", label: "Chart this month's revenue" },
  ]}
  onSelect={(suggestion) => chat.send(suggestion.prompt)}
  disabled={chat.status === "streaming"}
/>
```

## Examples [#examples]

### Scrolling row [#scrolling-row]

One line that scrolls sideways.

```tsx
"use client"

import { PromptSuggestions, type PromptSuggestion } from "@/components/ai/prompt-suggestions"

const sampleSuggestions: PromptSuggestion[] = [
  { id: "a", label: "Why did the nightly export fail?" },
  { id: "b", label: "Compare last two deploys" },
  { id: "c", label: "List open incidents" },
  { id: "d", label: "Who owns the billing service?" },
  { id: "e", label: "Show slowest endpoints" },
]

/** One line that scrolls sideways, for a narrow composer. */
export function PromptSuggestionsScroll() {
  return (
    <div className="w-full max-w-sm min-w-0">
      <PromptSuggestions layout="scroll" suggestions={sampleSuggestions} onSelect={() => {}} />
    </div>
  )
}

```

### List [#list]

Full-width rows in one block.

```tsx
"use client"

import { PromptSuggestions, type PromptSuggestion } from "@/components/ai/prompt-suggestions"

const sampleSuggestions: PromptSuggestion[] = [
  { id: "a", label: "Walk me through setting up SSO" },
  { id: "b", label: "Explain how usage is billed" },
  { id: "c", label: "Help me invite my team" },
]

/** Full-width rows, for longer prompts. */
export function PromptSuggestionsList() {
  return (
    <div className="w-full max-w-md min-w-0">
      <PromptSuggestions layout="list" suggestions={sampleSuggestions} onSelect={() => {}} />
    </div>
  )
}

```

## API reference [#api-reference]

### PromptSuggestions [#promptsuggestions]

Accepts native ul props beyond those listed.

| Prop          | Type                                                          | Default  | Description                                         |
| ------------- | ------------------------------------------------------------- | -------- | --------------------------------------------------- |
| `suggestions` | `PromptSuggestion[]`                                          | Required | The suggestions, in order.                          |
| `onSelect`    | `(suggestion: PromptSuggestion & { prompt: string }) => void` | Required | Called with the chosen suggestion.                  |
| `layout`      | `"wrap" \| "scroll" \| "list"`                                | `"wrap"` | Wrapping chips, one scrolling row, or stacked rows. |
| `disabled`    | `boolean`                                                     | `false`  | Turns every suggestion off.                         |
| `labels`      | `Partial<PromptSuggestionsLabels>`                            | English  | The list's accessible name.                         |

### Types [#types]

| Export             | Shape                                        |
| ------------------ | -------------------------------------------- |
| `PromptSuggestion` | `id`, `label`, and optional `prompt`, `icon` |
