Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Message
- Message Scroller
- Native Select
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
- Typography
AI Elements
Get Started
@shadcn/react
@shadcn/helpers
Utilities
"use client"
import * as React from "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>
)
}
Suggestion is a prompt you send without typing. Each one is a Button with the prompt as its label. Put a row of them above the Prompt Input.
Installation#
Suggestion is built with the Button component.
pnpm dlx shadcn@latest add button
Install the required shadcn/ui dependencies:
pnpm dlx shadcn@latest add button
Copy and paste the following code into your project.
"use client"
import type * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import {
Button as ButtonPrimitive,
Link as LinkPrimitive,
type ButtonProps as ButtonPrimitiveProps,
type LinkProps as LinkPrimitiveProps,
} from "react-aria-components"
const buttonVariants = cva(
"group/button inline-flex shrink-0 items-center justify-center rounded-2xl border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/80",
outline:
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:bg-transparent dark:hover:bg-input/30",
secondary:
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
ghost:
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
destructive:
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default:
"h-8 gap-1.5 px-3 has-data-[icon=inline-end]:pr-2.5 has-data-[icon=inline-start]:pl-2.5",
xs: "h-6 gap-1 px-2.5 text-xs has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3",
sm: "h-7 gap-1 px-3 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
lg: "h-9 gap-1.5 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
icon: "size-8",
"icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",
"icon-sm": "size-7",
"icon-lg": "size-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Button({
className,
variant = "default",
size = "default",
...props
}: Omit<ButtonPrimitiveProps, "className"> &
React.RefAttributes<HTMLButtonElement> &
VariantProps<typeof buttonVariants> & {
className?: string
}) {
return (
<ButtonPrimitive
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
function LinkButton({
className,
variant = "default",
size = "default",
...props
}: Omit<LinkPrimitiveProps, "className"> &
VariantProps<typeof buttonVariants> & {
className?: string
}) {
return (
<LinkPrimitive
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Button, LinkButton, buttonVariants }
Update the import paths to match your project setup.
Usage#
import { Button } from "@/components/ui/button"<div className="scrollbar-none flex scroll-fade-x 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>Scrolling#
The row scrolls sideways when the suggestions do not fit. scroll-fade-x fades the edge that has more to show, and shrink-0 keeps each label on one line.
AI SDK#
The label is the message. Send it as is.
sendMessage({ text: suggestion })Migrating from AI SDK Elements#
If you added Suggestion from AI SDK Elements, 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.
Migrate components/ai-elements/suggestion.tsx from AI SDK Elements to the shadcn/ui 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. Install Button: npx shadcn@latest add button
2. Read https://ui.shadcn.com/docs/ai-elements/aria/suggestion.md and build Suggestion the same way.
3. Rebuild each part:
- Suggestions renders a div with className="flex scroll-fade-x scrollbar-none 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 from the Button's onPress.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.Deploy your shadcn/ui app on Vercel
Trusted by OpenAI, Sonos, Adobe, and more.
Vercel provides tools and infrastructure to deploy apps and features at scale.
Deploy to Vercel