Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Suggestion for React

Prompt suggestions for a React chat on Base UI: a row of outline Buttons above the message field, each sending its label in one click.

On this page11 sections

Suggestions are short prompts in a row above the message field, and clicking one sends it as the person's message. They help on the first turn, when someone doesn't know what to ask, and after a reply, for the follow-ups an agent can predict.

Each suggestion is an outline Button with the prompt as its label, in a row that scrolls sideways when the labels don't fit. For chips that pick an option rather than send a message, use a Toggle Group.

Preview width

Installation

Suggestion is a pattern, so no suggestion file lands in your project. The command adds the two parts it's built from, Button and the scroll-fade utility, and the code to copy is the demo's.

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Suggestion anatomy: row, button, scroll-fade-x

Usage

import { Button } from "@/components/ui/button";

The row is a div that scrolls sideways, and each prompt is a small outline Button that calls your send function with its own label.

const suggestions = ["Add a dark mode toggle", "Fix the failing build"];

export function Suggestions(props: { onSend: (prompt: string) => void }) {
  return (
    <div className="scrollbar-none flex scroll-fade-x gap-2 overflow-x-auto overscroll-x-contain">
      {suggestions.map((suggestion) => (
        <Button
          className="shrink-0"
          key={suggestion}
          onClick={() => props.onSend(suggestion)}
          size="sm"
          variant="outline"
        >
          {suggestion}
        </Button>
      ))}
    </div>
  );
}

Button renders with type set to button unless you pass another, so the row can sit inside the message form without a click submitting it.

Accessibility

Each suggestion is a real button whose label is the prompt it sends, so a screen reader reads out exactly what a press will say. The row around the buttons is a plain div with no role, and Tab visits the buttons one by one. Nothing is announced when a suggestion is sent, so the transcript has to report the new message, as the Scrolling demo does with a polite live line under the row.

Tab
Moves focus to the next suggestion, scrolling the row to show it, and after the last one to whatever follows the row.
Shift+Tab
Moves focus to the previous suggestion.
Enter
Sends the focused suggestion.
Space
Sends the focused suggestion.

Demos

Scrolling

Five suggestions for an email thread, from Summarize this thread to Make it shorter, in a column as narrow as a phone's composer, with a line underneath naming the one that was sent. The row scrolls sideways, shrink-0 keeps each label on one line, and overscroll-x-contain stops a swipe at the end from scrolling the page. Wrap the row instead when every label fits, as in Wrapped.

Preview width

Wrapped

Four prompts for a pull request, from Summarize this pull request to Explain the diff, in a row with flex-wrap and no scrolling or fade. Every label stays in view, and the row grows a second line when they don't fit on one. Pick it for three or four short prompts in a wide composer, and the scrolling row on a phone.

Preview width

Follow-ups

A build agent whose suggestions live in state. Picking one sends it and empties the row while the reply is on its way, then the row fills with the follow-ups that reply offers, such as Cache the dependencies after a question about a slow build. The reply sits in a polite live region, so a screen reader hears it arrive.

Preview width

AI SDK

A suggestion's label is the message, so send it as it is.

import { useChat } from "@ai-sdk/react";

const { sendMessage, status } = useChat();
const busy = status === "submitted" || status === "streaming";

sendMessage({ text: suggestion });

Hide the row, or disable its buttons, while the chat's status is submitted or streaming, so a click can't drop a new message into the middle of a reply.

Migrating from AI SDK Elements

If you added Suggestion from AI SDK Elements (opens in a new tab), your project has a components/ai-elements/suggestion.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Button. Every export keeps its name and props, so the code that uses it keeps working.

Prompt
Migrate components/ai-elements/suggestion.tsx from AI SDK Elements to the shadcn.io Button component.

Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders.

1. Read https://www.shadcn.io/ui/suggestion.md and build Suggestion the same way. If the project doesn't have Button and the scroll-fade utility, run the command in its Installation section.
2. Rebuild each part:
   - Suggestions renders a div with className="scrollbar-none flex scroll-fade-x gap-2 overflow-x-auto overscroll-x-contain", instead of a ScrollArea. Change SuggestionsProps to ComponentProps<"div">.
   - Suggestion renders a Button with variant="outline", size="sm" and className="shrink-0". Keep onClick, called with the suggestion.
3. Remove the imports the file no longer uses.
4. Run the type checker and fix any errors.

FAQ

What should a Suggestion send when someone clicks it?

Its label, word for word, as the person's message, which is what every demo on this page does. People choose from what the button says, and a longer hidden prompt would put words in the transcript they never read. If a suggestion needs more context to work, put it in the system prompt or the request rather than in the message.

Keep labels short enough to read at a glance, about the length of the demo's "Fix the failing build".

How do I stop Suggestion buttons from sending while the agent is still replying?

Hide the row, or disable its buttons, while the chat is busy. With the AI SDK, that is while status is submitted or streaming. The Follow-ups demo empties the row while its reply is on the way.

To disable them, set disabled on each Button. Bring the row back, or a fresh set of follow-ups, once the reply ends.

How do I show follow-up suggestions after the agent replies?

Keep the suggestions in state rather than a constant, and replace them when a reply finishes, as the Follow-ups demo does. Your server decides what they are, either by asking the model for a few follow-ups alongside its answer or by deriving them from the conversation.

With the AI SDK, the route can stream them as a custom data part of the assistant's message, and the row reads them from the last message once the chat is ready again. Clear the row when the person sends, so old follow-ups don't linger under a new question.

Why does the Suggestion row fade at its edges?

The row has the scroll-fade-x class from the scroll-fade utility, which masks an edge so a cut-off label reads as more to scroll rather than a broken layout. In browsers with scroll-driven animations, an edge fades only while there is more past it, so the start stays sharp until you scroll. Other browsers keep a fade on both edges.

The fade flips sides in a right-to-left page. Remove the class, or add scroll-fade-none, on a row that wraps.

How do I wrap Suggestion buttons onto several lines instead of scrolling?

Change the row's classes: keep flex and gap-2, add flex-wrap, and drop overflow-x-auto, overscroll-x-contain, scrollbar-none and scroll-fade-x. Every button then stays in view, and a label that doesn't fit moves to the next line instead of off the edge, as in the Wrapped demo.

Wrapping suits three or four short prompts in a wide composer. With five or more on a phone, a wrapped row pushes the message field down by several lines, and the one-line row of the Scrolling demo fits better.

Can keyboard users reach Suggestion buttons in a scrolling row?

Yes. Each suggestion is a button in the tab order, so Tab moves through them in order and Enter or Space sends the focused one. When focus lands on a label that's scrolled out of view, the browser scrolls the row to show it, so the hidden ones are reachable without a mouse.

The row has no arrow-key navigation, so six suggestions are six Tab stops before the message field. That is one more reason to keep the list short.

Is this the same as AI SDK Elements' Suggestion?

It does the same job without a wrapper. In AI SDK Elements, Suggestions was a ScrollArea and each Suggestion a Button, and here the row is a div with the scroll-fade utility around plain Buttons. The Migrating from AI SDK Elements section has a prompt for your coding agent that rebuilds the old suggestion.tsx on these parts and keeps its exports.

API Reference

Suggestion has no props of its own. Each suggestion is a Button, so variant, size and the click handler are Button's. The row is a div with the scroll-fade utility's scroll-fade-x class.