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, ChevronDownIcon, PlusIcon } from "lucide-react"
import {
DropdownMenu,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupTextarea,
} from "@/components/ui/input-group"
const providers = [
{
name: "OpenAI",
models: [
{ id: "gpt-5", name: "GPT-5" },
{ id: "gpt-5-mini", name: "GPT-5 mini" },
],
},
{
name: "Anthropic",
models: [
{ id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" },
{ id: "claude-haiku-4-5", name: "Claude Haiku 4.5" },
],
},
]
const models = providers.flatMap((provider) => provider.models)
const efforts = [
{ id: "low", name: "Low" },
{ id: "medium", name: "Medium" },
{ id: "high", name: "High" },
]
export function ModelSelectorDemo() {
const [text, setText] = React.useState("")
const [model, setModel] = React.useState(models[0].id)
const [effort, setEffort] = React.useState(efforts[1].id)
const formRef = React.useRef<HTMLFormElement>(null)
const currentModel = models.find((item) => item.id === model) ?? models[0]
const currentEffort = efforts.find((item) => item.id === effort) ?? efforts[1]
const canSend = text.trim().length > 0
function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault()
if (!canSend) {
return
}
setText("")
}
return (
<div className="mx-auto w-full max-w-lg py-6">
<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
type="submit"
size="icon-sm"
variant="outline"
className="rounded-full"
isDisabled={canSend}
aria-label="Attach"
>
<PlusIcon />
</InputGroupButton>
<DropdownMenuTrigger>
<InputGroupButton
size="sm"
variant="outline"
aria-label={`Model: ${currentModel.name}`}
className="ml-auto"
>
{currentModel.name}
<ChevronDownIcon />
</InputGroupButton>
<DropdownMenu
className="w-48"
selectionMode="single"
disallowEmptySelection
selectedKeys={[model]}
onSelectionChange={(keys) => setModel([...keys][0] as string)}
>
{providers.map((provider, index) => (
<React.Fragment key={provider.name}>
{index > 0 && <DropdownMenuSeparator />}
<DropdownMenuGroup>
<DropdownMenuLabel>{provider.name}</DropdownMenuLabel>
{provider.models.map((item) => (
<DropdownMenuItem key={item.id} id={item.id}>
{item.name}
</DropdownMenuItem>
))}
</DropdownMenuGroup>
</React.Fragment>
))}
</DropdownMenu>
</DropdownMenuTrigger>
<DropdownMenuTrigger>
<InputGroupButton
size="sm"
variant="outline"
aria-label={`Effort: ${currentEffort.name}`}
>
<span className="text-muted-foreground">Effort</span>
{currentEffort.name}
<ChevronDownIcon />
</InputGroupButton>
<DropdownMenu
className="w-36"
selectionMode="single"
disallowEmptySelection
selectedKeys={[effort]}
onSelectionChange={(keys) => setEffort([...keys][0] as string)}
>
<DropdownMenuGroup>
<DropdownMenuLabel>Effort</DropdownMenuLabel>
{efforts.map((item) => (
<DropdownMenuItem key={item.id} id={item.id}>
{item.name}
</DropdownMenuItem>
))}
</DropdownMenuGroup>
</DropdownMenu>
</DropdownMenuTrigger>
<InputGroupButton
type="submit"
size="icon-sm"
variant="default"
className="rounded-full"
isDisabled={!canSend}
aria-label="Send"
>
<ArrowUpIcon />
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
</form>
</div>
)
}
Installation#
Model Selector is built with the Dropdown Menu and Input Group components.
pnpm dlx shadcn@latest add dropdown-menu input-group
Install the required shadcn/ui dependencies:
pnpm dlx shadcn@latest add dropdown-menu input-group
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { cva } from "class-variance-authority"
import { cn } from "cn"
import { CheckIcon, ChevronRightIcon } from "lucide-react"
import {
composeRenderProps,
Header as HeaderPrimitive,
MenuItem as MenuItemPrimitive,
Menu as MenuPrimitive,
MenuSection as MenuSectionPrimitive,
MenuTrigger as MenuTriggerPrimitive,
Popover as PopoverPrimitive,
Separator as SeparatorPrimitive,
SubmenuTrigger as SubmenuTriggerPrimitive,
type MenuItemProps as MenuItemPrimitiveProps,
type MenuSectionProps as MenuSectionPrimitiveProps,
} from "react-aria-components"
function DropdownMenuTrigger({
...props
}: React.ComponentProps<typeof MenuTriggerPrimitive>) {
return <MenuTriggerPrimitive data-slot="dropdown-menu-trigger" {...props} />
}
function DropdownMenu({
"data-slot": dataSlot = "dropdown-menu-content",
placement = "bottom start",
offset = 4,
crossOffset = 0,
className,
children,
...props
}: Omit<
React.ComponentProps<typeof MenuPrimitive<object>>,
"children" | "className"
> &
Pick<
React.ComponentProps<typeof PopoverPrimitive>,
"placement" | "offset" | "crossOffset"
> & {
"data-slot"?: string
className?: string
children?: React.ReactNode
}) {
return (
<PopoverPrimitive
data-slot={dataSlot}
placement={placement}
offset={offset}
crossOffset={crossOffset}
className={cn("z-50 w-(--trigger-width) min-w-32 origin-(--trigger-anchor-point) overflow-x-hidden overflow-y-auto rounded-2xl bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/5 duration-100 outline-none data-entering:animate-in data-entering:fade-in-0 data-entering:zoom-in-95 data-exiting:animate-out data-exiting:overflow-hidden data-exiting:fade-out-0 data-exiting:zoom-out-95 data-[placement=bottom]:slide-in-from-top-2 data-[placement=left]:slide-in-from-right-2 data-[placement=right]:slide-in-from-left-2 data-[placement=top]:slide-in-from-bottom-2 **:data-[slot$=-item]:data-focused:bg-foreground/10 dark:ring-foreground/10", className )}
>
<MenuPrimitive
className="max-h-[inherit] overflow-x-hidden overflow-y-auto outline-hidden"
{...props}
>
{children}
</MenuPrimitive>
</PopoverPrimitive>
)
}
function DropdownMenuGroup({
...props
}: Omit<MenuSectionPrimitiveProps<object>, "children"> & {
children?: React.ReactNode
}) {
return <MenuSectionPrimitive data-slot="dropdown-menu-group" {...props} />
}
function DropdownMenuLabel({
className,
inset,
...props
}: React.ComponentProps<typeof HeaderPrimitive> & {
inset?: boolean
}) {
return (
<HeaderPrimitive
data-slot="dropdown-menu-label"
data-inset={inset}
className={cn(
"px-2 py-1 text-xs text-muted-foreground data-inset:pl-7",
className
)}
{...props}
/>
)
}
const dropdownMenuItemVariants = cva(
"group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
{
variants: {
selectionMode: {
none: "min-h-7 gap-2 rounded-xl px-2 py-1.5 text-sm focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
single:
"min-h-7 gap-2 rounded-xl py-1.5 pr-8 pl-2 text-sm focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4",
multiple:
"min-h-7 gap-2 rounded-xl py-1.5 pr-8 pl-2 text-sm focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4",
},
},
}
)
function DropdownMenuItem({
className,
inset,
variant = "default",
children,
...props
}: MenuItemPrimitiveProps<object> & {
inset?: boolean
variant?: "default" | "destructive"
}) {
return (
<MenuItemPrimitive
data-slot="dropdown-menu-item"
data-inset={inset}
data-variant={variant}
textValue={typeof children === "string" ? children : props.textValue}
className={composeRenderProps(className, (className, { selectionMode }) =>
cn(dropdownMenuItemVariants({ selectionMode }), className)
)}
{...props}
>
{composeRenderProps(
children,
(children, { isSelected, selectionMode }) => (
<>
{selectionMode !== "none" ? (
<span
className="pointer-events-none absolute right-2 flex items-center justify-center"
data-slot={
selectionMode === "single"
? "dropdown-menu-radio-item-indicator"
: "dropdown-menu-checkbox-item-indicator"
}
>
{isSelected ? <CheckIcon /> : null}
</span>
) : null}
{children}
</>
)
)}
</MenuItemPrimitive>
)
}
function DropdownMenuSub({
...props
}: React.ComponentProps<typeof SubmenuTriggerPrimitive>) {
return <SubmenuTriggerPrimitive data-slot="dropdown-menu-sub" {...props} />
}
function DropdownMenuSubTrigger({
className,
inset,
children,
...props
}: MenuItemPrimitiveProps<object> & {
inset?: boolean
}) {
return (
<MenuItemPrimitive
data-slot="dropdown-menu-sub-trigger"
data-inset={inset}
textValue={typeof children === "string" ? children : props.textValue}
className={cn(
"flex min-h-7 cursor-default items-center gap-2 rounded-xl px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
{composeRenderProps(children, (children) => (
<>
{children}
<ChevronRightIcon className="cn-rtl-flip ml-auto" />
</>
))}
</MenuItemPrimitive>
)
}
function DropdownMenuSubContent({
placement = "end top",
crossOffset = -3,
offset = 0,
className,
...props
}: React.ComponentProps<typeof DropdownMenu>) {
return (
<DropdownMenu
data-slot="dropdown-menu-sub-content"
className={cn("w-auto min-w-[96px] rounded-2xl bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/5 duration-100 dark:ring-foreground/10", className )}
placement={placement}
crossOffset={crossOffset}
offset={offset}
{...props}
/>
)
}
function DropdownMenuSeparator({
className,
...props
}: React.ComponentProps<typeof SeparatorPrimitive>) {
return (
<SeparatorPrimitive
data-slot="dropdown-menu-separator"
className={cn("-mx-1 my-1 h-px bg-border/50", className)}
{...props}
/>
)
}
function DropdownMenuShortcut({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
data-slot="dropdown-menu-shortcut"
className={cn(
"ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",
className
)}
{...props}
/>
)
}
export {
DropdownMenuTrigger,
DropdownMenu,
DropdownMenuGroup,
DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubTrigger,
DropdownMenuSubContent,
}
Update the import paths to match your project setup.
Usage#
import { ArrowUpIcon, ChevronDownIcon } from "lucide-react"
import {
DropdownMenu,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupTextarea,
} from "@/components/ui/input-group"<InputGroup>
<InputGroupTextarea placeholder="Ask the agent to change your code..." />
<InputGroupAddon align="block-end">
<DropdownMenuTrigger>
<InputGroupButton size="sm">
GPT-5
<ChevronDownIcon />
</InputGroupButton>
<DropdownMenu
selectionMode="single"
disallowEmptySelection
selectedKeys={[model]}
onSelectionChange={(keys) => setModel([...keys][0] as string)}
>
<DropdownMenuGroup>
<DropdownMenuLabel>OpenAI</DropdownMenuLabel>
<DropdownMenuItem id="gpt-5">GPT-5</DropdownMenuItem>
<DropdownMenuItem id="gpt-5-mini">GPT-5 mini</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenu>
</DropdownMenuTrigger>
<DropdownMenuTrigger>
<InputGroupButton size="sm">
Medium
<ChevronDownIcon />
</InputGroupButton>
<DropdownMenu
selectionMode="single"
disallowEmptySelection
selectedKeys={[effort]}
onSelectionChange={(keys) => setEffort([...keys][0] as string)}
>
<DropdownMenuItem id="low">Low</DropdownMenuItem>
<DropdownMenuItem id="medium">Medium</DropdownMenuItem>
<DropdownMenuItem id="high">High</DropdownMenuItem>
</DropdownMenu>
</DropdownMenuTrigger>
<InputGroupButton type="submit" variant="default" className="ml-auto">
<ArrowUpIcon />
</InputGroupButton>
</InputGroupAddon>
</InputGroup>AI SDK#
Send the model and the effort with the message. Map them to a model and provider options in the route.
sendMessage({ text }, { body: { model, effort } })import { anthropic } from "@ai-sdk/anthropic"
import { openai } from "@ai-sdk/openai"
import { convertToModelMessages, streamText, type UIMessage } from "ai"
const models = {
"gpt-5": openai("gpt-5"),
"gpt-5-mini": openai("gpt-5-mini"),
"claude-sonnet-4-5": anthropic("claude-sonnet-4-5"),
"claude-haiku-4-5": anthropic("claude-haiku-4-5"),
}
export async function POST(req: Request) {
const { messages, model, effort } = (await req.json()) as {
messages: UIMessage[]
model: keyof typeof models
effort: "low" | "medium" | "high"
}
const result = streamText({
model: models[model] ?? models["gpt-5"],
messages: await convertToModelMessages(messages),
providerOptions: {
openai: { reasoningEffort: effort },
anthropic: { effort },
},
})
return result.toUIMessageStreamResponse()
}Each provider reads its own key in providerOptions and ignores the rest.
Migrating from AI SDK Elements#
If you added Model Selector from AI SDK Elements, your project has a components/ai-elements/model-selector.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Dropdown Menu. Every export keeps its name and props, so the code that uses it keeps working.
Migrate components/ai-elements/model-selector.tsx from AI SDK Elements to the shadcn/ui Dropdown Menu 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 Dropdown Menu: npx shadcn@latest add dropdown-menu
2. Read https://ui.shadcn.com/docs/ai-elements/aria/model-selector.md and build Model Selector the same way.
3. Rebuild each part:
- ModelSelector renders a DropdownMenuTrigger, instead of a Dialog. ModelSelectorTrigger renders the Button inside it.
- ModelSelectorContent and ModelSelectorList render a DropdownMenu with selectionMode="single", disallowEmptySelection and the selected model in selectedKeys.
- ModelSelectorGroup renders a DropdownMenuGroup with a DropdownMenuLabel for its heading.
- ModelSelectorItem renders a DropdownMenuItem with the model as its id. Picking a model closes the menu.
- ModelSelectorSeparator renders a DropdownMenuSeparator, and ModelSelectorShortcut a DropdownMenuShortcut.
- A menu has no search field. Keep ModelSelectorInput, ModelSelectorEmpty and ModelSelectorDialog on Command if you use search, or remove them if nothing imports them.
- Keep ModelSelectorLogo, ModelSelectorLogoGroup and ModelSelectorName as they are.
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