Suggestion
A row of ready-made prompts the person can send with one press.
Installation
pnpm dlx shadcn@latest add @silkware/ai-suggestionTo copy the pattern by hand, install the components it composes:
pnpm dlx shadcn@latest add @silkware/bubble @silkware/button @silkware/input-group @silkware/messageThen install the icon package and copy the pattern into components/ai-elements/suggestion.tsx:
pnpm add lucide-react"use client"
import * as React from "react"import { ArrowUpIcon, PlusIcon } from "lucide-react"
import { Bubble, BubbleContent } from "@/components/ui/bubble"import { Button } from "@/components/ui/button"import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea,} from "@/components/ui/input-group"import { Message, MessageContent } from "@/components/ui/message"
const suggestions = [ "Add a dark mode toggle", "Fix the failing build", "Write tests for the form", "Upgrade to Next.js 16", "Add a loading state", "Find unused dependencies",]
const replies: Record<string, string> = { "Add a dark mode toggle": "Added a ModeToggle to the site header. It calls setTheme from next-themes.", "Fix the failing build": "The build failed on a missing import in app/page.tsx. I added it and the build passes.", "Write tests for the form": "Added four tests in signup-form.test.tsx. They cover the empty, invalid and valid states.", "Upgrade to Next.js 16": "Ran the codemod and bumped next to 16. Two routes needed async params, so I updated them.", "Add a loading state": "Added a loading.tsx to the dashboard route. It shows skeletons while the data loads.", "Find unused dependencies": "Three packages are not imported anywhere: lodash, moment and classnames. Should I remove them?",}
export function SuggestionDemo() { const [text, setText] = React.useState("") const [turn, setTurn] = React.useState<{ prompt: string reply: string } | null>(null) const formRef = React.useRef<HTMLFormElement>(null) const canSend = text.trim().length > 0
function send(prompt: string) { setTurn({ prompt, reply: replies[prompt] ?? "This demo only knows the suggestions. Pick one.", }) setText("") }
function onSubmit(event: React.FormEvent<HTMLFormElement>) { event.preventDefault() if (!canSend) { return }
send(text.trim()) }
return ( <div className="mx-auto flex w-full max-w-lg flex-col gap-6 py-6 text-sm"> {turn && ( <div className="flex flex-col gap-4"> <Message align="end"> <MessageContent> <Bubble align="end" variant="muted"> <BubbleContent>{turn.prompt}</BubbleContent> </Bubble> </MessageContent> </Message> <Message> <MessageContent> <p>{turn.reply}</p> </MessageContent> </Message> </div> )} <div className="flex flex-col gap-2"> <div className="flex scroll-fade-x scrollbar-none gap-2 overflow-x-auto overscroll-x-contain"> {suggestions.map((suggestion) => ( <Button key={suggestion} variant="outline" size="sm" className="shrink-0" onPress={() => send(suggestion)} > {suggestion} </Button> ))} </div> <form ref={formRef} onSubmit={onSubmit}> <InputGroup> <InputGroupTextarea value={text} onChange={(event) => { setText( typeof event === "string" ? event : event.currentTarget.value ) }} placeholder="Ask the agent to change your code..." onKeyDown={(event) => { if (event.key === "Enter" && !event.shiftKey) { event.preventDefault() formRef.current?.requestSubmit() } }} className="p-3" /> <InputGroupAddon align="block-end"> <InputGroupButton size="icon-sm" variant="outline" className="rounded-full" aria-label="Attach files" > <PlusIcon /> </InputGroupButton> <InputGroupButton type="submit" size="icon-sm" variant="default" className="ml-auto rounded-full" isDisabled={!canSend} aria-label="Send" > <ArrowUpIcon /> </InputGroupButton> </InputGroupAddon> </InputGroup> </form> </div> </div> )}Usage
import { Button } from "@/components/ui/button"<div className="flex scroll-fade-x scrollbar-none gap-2 overflow-x-auto overscroll-x-contain"> {suggestions.map((suggestion) => ( <Button key={suggestion} variant="outline" size="sm" className="shrink-0" onPress={() => send(suggestion)} > {suggestion} </Button> ))}</div>A suggestion is a button that sends its own text as the next message. The row scrolls sideways, with the edges faded by scroll-fade-x, so a long list stays on one line above the field. Use onPress, as on any Button.
In the demo, send(prompt) shows the prompt and its canned reply. Replace it with sendMessage({ text: suggestion }).
Examples
Wrapping
In an empty thread there is room to show every suggestion. Let the buttons wrap, and fill the field instead of sending, so the person can edit the prompt first.
AI SDK
Send a suggestion exactly as a typed message. Hide the row when the thread has begun, or when the agent is running.
const { messages, sendMessage, status } = useChat()const busy = status === "submitted" || status === "streaming"
{messages.length === 0 && suggestions.map((suggestion) => ( <Button key={suggestion} variant="outline" size="sm" isDisabled={busy} onPress={() => sendMessage({ text: suggestion })} > {suggestion} </Button> ))}The AI SDK has no suggestion type. A model can propose follow-ups as a typed data part, for example data-suggestions with a list of strings, which you render as the same buttons. That is your own schema; check that the strings come from your route, not from page content.
Offline, the demo uses a local lookup of suggestion text to reply text. createChat in lib/ai.ts works too: script a reply for each suggestion and send it with chat.next.
Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus to the next suggestion, then to the field. |
| Enter | Sends the focused suggestion. |
| Space | Sends the focused suggestion. |
The composed components provide:
- Real buttons, each with a visible focus ring and press behaviour that is the same for mouse, touch and keyboard.
- A row that scrolls with the pointer and with focus: tabbing to an off-screen suggestion scrolls it into view.
You provide:
- Suggestion text that makes sense read alone, since each button is announced by its text.
- A group label if the row needs one, such as
role="group"witharia-label="Suggested prompts". - Focus handling after a send: the row can disappear, so move focus to the field or the new message.
Guidelines
When to use
- In an empty thread, to show what the agent can do.
- After a reply, to offer the most likely next step.
When not to use
- To list actions the agent is about to take. Use Confirmation or Plan.
- For navigation. Use Tabs or links.
Content
- Write each suggestion as the message the person would send, in their voice: "Compare the two latest price lists".
- Keep it under about six words where you can, and offer three to six.
- Do not suggest anything the agent cannot do.
Human in the loop
A suggestion sends a message on the person's behalf, so the text on the button must be exactly what is sent. Never pad a suggestion with hidden instructions. For anything that changes data, let the suggestion fill the field instead of sending, so the person reads it first.
Show the whole message on the button, and send exactly that.
Don’t label a button "Fix it" and send a longer prompt the person never saw.
Composition
| Component | What it does here |
|---|---|
| Button | One suggestion: an outline button at small size. |
| Input Group | The field below the row. |
| Message and Bubble | Show the prompt that was sent and the reply in the demo. |
The pattern exports one component, SuggestionDemo. The suggestions list and the replies lookup at the top of the file are sample data.