Suggestion
A short prompt you can send to the agent in one click.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { For, createSignal } from "solid-js"
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 default function SuggestionDemo() {
const [text, setText] = createSignal("")
const [turn, setTurn] = createSignal<{
prompt: string
reply: string
} | null>(null)
let formRef: HTMLFormElement | undefined
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: SubmitEvent & { currentTarget: HTMLFormElement }) {
event.preventDefault()
if (!canSend()) {
return
}
send(text().trim())
}
return (
<div class="mx-auto flex w-full max-w-lg flex-col gap-6 py-6 text-sm">
{turn() && (
<div class="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 class="flex flex-col gap-2">
<div class="flex scrollbar-none gap-2 overflow-x-auto overscroll-x-contain scroll-fade-x">
{
<For each={suggestions}>
{(suggestion) => (
<Button
variant="outline"
size="sm"
class="shrink-0"
onClick={() => send(suggestion)}
>
{suggestion}
</Button>
)}
</For>
}
</div>
<form
ref={(element) => {
formRef = element
}}
onSubmit={onSubmit}
>
<InputGroup>
<InputGroupTextarea
value={text()}
onInput={(event) => setText(event.currentTarget.value)}
placeholder="Ask the agent to change your code..."
onKeyDown={(event) => {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault()
formRef?.requestSubmit()
}
}}
class="p-3"
/>
<InputGroupAddon align="block-end">
<InputGroupButton
size="icon-sm"
variant="outline"
class="rounded-full"
aria-label="Attach files"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M5 12h14" />
<path d="M12 5v14" />
</svg>
</InputGroupButton>
<InputGroupButton
type="submit"
size="icon-sm"
variant="default"
class="ml-auto rounded-full"
disabled={!canSend()}
aria-label="Send"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m5 12 7-7 7 7" />
<path d="M12 19V5" />
</svg>
</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.
Install the required Solid UI dependencies:
Copy and paste the following code into your project.
import { dynamic, type ComponentProps, type ValidComponent } from "@solidjs/web"
import { cva, type VariantProps } from "class-variance-authority"
import { isStatic, omit } from "solid-js"
import { cn } from "~/lib/utils"
const buttonVariants = cva(
"group/button rounded-lg border border-transparent bg-clip-padding text-sm font-medium focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px 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:not([class*='size-'])]:size-4 inline-flex shrink-0 items-center justify-center whitespace-nowrap transition-all outline-none select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
{
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:border-input dark:bg-input/30 dark:hover:bg-input/50",
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-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
icon: "size-8",
"icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
"icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
"icon-lg": "size-9"
}
},
defaultVariants: {
variant: "default",
size: "default"
}
}
)
type ButtonProps<T extends ValidComponent = "button"> = Omit<
ComponentProps<NoInfer<T>>,
"as" | "class" | "variant" | "size"
> &
VariantProps<typeof buttonVariants> & {
as?: T
class?: string
}
function Button<T extends ValidComponent = "button">(props: ButtonProps<T>) {
const Comp = dynamic<ValidComponent>(() => props.as ?? "button", {
static: isStatic(props, "as")
})
const rest = omit(props, "as", "class", "variant", "size")
return (
<Comp
type={(props.as ?? "button") === "button" ? "button" : undefined}
data-slot="button"
data-variant={props.variant === undefined ? "default" : props.variant}
data-size={props.size === undefined ? "default" : props.size}
class={cn(
buttonVariants({ variant: props.variant, size: props.size }),
props.class
)}
{...rest}
/>
)
}
export { Button, buttonVariants, type ButtonProps }Update the import paths to match your project setup.
Usage
import { Button } from "~/components/ui/button"import { For } from "solid-js"
;<div class="scrollbar-none flex scroll-fade-x gap-2 overflow-x-auto overscroll-x-contain">
{
<For each={suggestions}>
{(suggestion) => (
<Button
variant="outline"
size="sm"
class="shrink-0"
onClick={() => send(suggestion)}
>
{suggestion}
</Button>
)}
</For>
}
</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 Solid 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 solidui-cli@latest add button
2. Read https://www.solid-ui.com/docs/ai-elements/suggestion.md and build Suggestion the same way.
3. Rebuild each part:
- Suggestions renders a div with class="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 class="shrink-0". Keep onClick, called with the suggestion.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.