import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import {
inputGroupClass, inputGroupAddonClass, inputGroupButtonClass, inputGroupTextareaClass,
} from '#components/ui/input-group.ts';
import { ArrowUpIcon, ChevronDownIcon, PlusIcon } from '#lib/ui/lucide.ts';
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 efforts = [
{ id: 'low', name: 'Low' },
{ id: 'medium', name: 'Medium' },
{ id: 'high', name: 'High' },
];
const model = providers[0].models[0];
const effort = efforts[1];
// The field before anything is typed, so Send starts disabled. The attach
// button is a <label> for the hidden file input, which opens the file picker
// with no script. Showing the picked files as attachments, enabling Send and
// submitting on Enter are the reader's to wire (see Attachments and Keyboard).
export default function PromptInputDemo() {
return html`
<div class="mx-auto w-full max-w-lg py-6">
<form>
<input id="prompt-input-files" type="file" name="files" multiple tabindex="-1" class="sr-only">
<div data-slot="input-group" role="group" class=${inputGroupClass()}>
<textarea data-slot="input-group-control" name="text" placeholder="Ask the agent to change your code..." aria-label="Message" class=${cn(inputGroupTextareaClass(), 'p-3')}></textarea>
<div role="group" data-slot="input-group-addon" data-align="block-end" class=${inputGroupAddonClass({ align: 'block-end' })}>
<label for="prompt-input-files" aria-label="Attach files" data-slot="button" data-variant="outline" data-size="icon-sm" class=${cn(inputGroupButtonClass({ variant: 'outline', size: 'icon-sm' }), 'cursor-pointer rounded-full')}>
${PlusIcon()}
</label>
<ui-dropdown-menu class="ml-auto">
<ui-dropdown-menu-trigger>
<button type="button" aria-label=${`Model: ${model.name}`} data-slot="button" data-variant="outline" data-size="sm" class=${inputGroupButtonClass({ variant: 'outline', size: 'sm' })}>
${model.name}
${ChevronDownIcon()}
</button>
</ui-dropdown-menu-trigger>
<ui-dropdown-menu-content align="start" class="w-48">
<ui-dropdown-menu-group aria-label="Model">
${providers.map((provider, index) => html`
${index > 0 ? html`<ui-dropdown-menu-separator></ui-dropdown-menu-separator>` : ''}
<ui-dropdown-menu-label>${provider.name}</ui-dropdown-menu-label>
${provider.models.map((item) => html`
<ui-dropdown-menu-item type="radio" value=${item.id} ?checked=${item.id === model.id}>${item.name}</ui-dropdown-menu-item>
`)}
`)}
</ui-dropdown-menu-group>
</ui-dropdown-menu-content>
</ui-dropdown-menu>
<ui-dropdown-menu>
<ui-dropdown-menu-trigger>
<button type="button" aria-label=${`Effort: ${effort.name}`} data-slot="button" data-variant="outline" data-size="sm" class=${inputGroupButtonClass({ variant: 'outline', size: 'sm' })}>
<span class="text-muted-foreground">Effort</span>
${effort.name}
${ChevronDownIcon()}
</button>
</ui-dropdown-menu-trigger>
<ui-dropdown-menu-content align="start" class="w-36">
<ui-dropdown-menu-group>
<ui-dropdown-menu-label>Effort</ui-dropdown-menu-label>
<ui-dropdown-menu-group aria-label="Effort">
${efforts.map((item) => html`
<ui-dropdown-menu-item type="radio" value=${item.id} ?checked=${item.id === effort.id}>${item.name}</ui-dropdown-menu-item>
`)}
</ui-dropdown-menu-group>
</ui-dropdown-menu-group>
</ui-dropdown-menu-content>
</ui-dropdown-menu>
<button type="submit" disabled aria-label="Send" data-slot="button" data-variant="default" data-size="icon-sm" class=${cn(inputGroupButtonClass({ variant: 'default', size: 'icon-sm' }), 'rounded-full')}>
${ArrowUpIcon()}
</button>
</div>
</div>
</form>
</div>
`;
}
View Code
Prompt Input is the field the person types into to message the agent. It is an Input Group with a textarea, an attach button, the Model Selector menus and a send button. Attached files show as Attachment chips above the text.
Installation
Prompt Input is built with the Input Group, Attachment and Dropdown Menu components.
Install the following dependencies:
Copy and paste the following code into your project.
/**
* Input group: an input or textarea with addons inside its border (an icon, a
* prefix such as "https://", a button, a counter), sharing one focus ring.
* Tier-1 class helper; compose with a real `<input>` or `<textarea>`.
*
* shadcn parity:
* InputGroup → inputGroupClass()
* InputGroupAddon (align: inline-start | inline-end | block-start | block-end)
* → inputGroupAddonClass({ align }), alias inputGroupAddonVariants,
* plus the same `data-align` on the addon (the styles pad the
* control beside it by it)
* InputGroupButton (size) → inputGroupButtonClass({ size }) with buttonClass({ variant })
* InputGroupText → inputGroupTextClass()
* InputGroupInput / InputGroupTextarea
* → inputGroupInputClass() / inputGroupTextareaClass()
*
* The group draws the border and the focus ring, so the control inside drops
* its own. Clicking an addon focuses the control through a `<label for>`, with
* no script: make the addon a `<label>` pointing at the control's id.
*
* A11y (required for accessible output): the control still needs its own
* accessible name, from a visible `<label for>` outside the group or an
* `aria-label` on the control; an addon's text is not its name. A decorative
* icon addon takes `aria-hidden="true"`. An addon button is a real
* `<button type="button">` with its own name.
*
* Design tokens used: --input, --ring, --muted-foreground, --destructive.
*
* @example
* ```html
* <div class=${inputGroupClass()} data-slot="input-group" role="group">
* <label class=${inputGroupAddonClass()} data-slot="input-group-addon" data-align="inline-start" for="site">https://</label>
* <input class=${inputGroupInputClass()} data-slot="input-group-control" id="site" name="site" aria-label="Website">
* </div>
* ```
*/
import { cn } from '../lib/utils.ts';
import { inputClass } from './input.ts';
import { textareaClass } from './textarea.ts';
import { buttonClass, type ButtonVariant } from './button.ts';
/** Set `data-slot="input-group"` on the element. */
export function inputGroupClass(): string {
return 'rounded-md border border-input shadow-xs transition-[color,box-shadow] dark:bg-input/30 has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3 group/input-group relative flex w-full min-w-0 items-center outline-none has-[>textarea]:h-auto';
}
const INPUT_GROUP_ADDON_BASE =
"h-auto gap-2 py-1.5 text-sm font-medium text-muted-foreground group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4 flex cursor-text items-center justify-center select-none";
const INPUT_GROUP_ADDON_ALIGNS = {
'inline-start': 'ps-3 has-[>button]:ms-[-0.45rem] has-[>kbd]:ms-[-0.35rem] order-first',
'inline-end': 'pe-3 has-[>button]:me-[-0.45rem] has-[>kbd]:me-[-0.35rem] order-last',
'block-start': 'px-3 pt-3 group-has-[>input]/input-group:pt-2.5 [.border-b]:pb-3 order-first w-full justify-start',
'block-end': 'px-3 pb-3 group-has-[>input]/input-group:pb-2.5 [.border-t]:pt-3 order-last w-full justify-start',
} as const;
/** The part, with its variant options. Set its `data-slot` and any `data-variant` / `data-size` to match. */
export function inputGroupAddonClass(opts: { align?: keyof typeof INPUT_GROUP_ADDON_ALIGNS } & { className?: string } = {}): string {
return cn(INPUT_GROUP_ADDON_BASE, INPUT_GROUP_ADDON_ALIGNS[opts.align ?? 'inline-start'], opts.className);
}
/**
* shadcn's name for {@link inputGroupAddonClass}, so shadcn code ports verbatim. Like cva,
* it merges a `className` into the result.
*/
export function inputGroupAddonVariants(opts: { align?: keyof typeof INPUT_GROUP_ADDON_ALIGNS } & { className?: string } = {}): string {
return inputGroupAddonClass(opts);
}
const INPUT_GROUP_BUTTON_BASE =
'gap-2 text-sm flex items-center shadow-none';
const INPUT_GROUP_BUTTON_SIZES = {
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",
sm: 'h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5',
'icon-xs': 'size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0',
'icon-sm': 'size-8 p-0 has-[>svg]:p-0',
} as const;
/**
* The part, with its variant options. Set its `data-slot` and any `data-variant` / `data-size` to match.
*
* shadcn's InputGroupButton IS its Button (`variant` defaulting to ghost)
* with these classes on top, so the button's own classes come first and the
* group's size wins a conflict.
*/
export function inputGroupButtonClass(opts: { size?: keyof typeof INPUT_GROUP_BUTTON_SIZES; variant?: ButtonVariant } & { className?: string } = {}): string {
return cn(buttonClass({ variant: opts.variant ?? 'ghost' }), INPUT_GROUP_BUTTON_BASE, INPUT_GROUP_BUTTON_SIZES[opts.size ?? 'xs'], opts.className);
}
/**
* shadcn's name for {@link inputGroupButtonClass}, so shadcn code ports verbatim. Like cva,
* it merges a `className` into the result.
*/
export function inputGroupButtonVariants(opts: { size?: keyof typeof INPUT_GROUP_BUTTON_SIZES; variant?: ButtonVariant } & { className?: string } = {}): string {
return inputGroupButtonClass(opts);
}
/** A part with no `data-slot` of its own. */
export function inputGroupTextClass(): string {
return "gap-2 text-sm text-muted-foreground [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none";
}
/**
* Set `data-slot="input-group-control"` on the element. shadcn's
* InputGroupInput is its Input with these classes on top, so the input's own
* base (its `outline-none` and focus treatment included) comes first and the
* group's resets win a conflict. Without it a focused control shows the
* browser's own outline inside the group's ring.
*/
export function inputGroupInputClass(): string {
return cn(inputClass(), 'rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent flex-1');
}
/** Set `data-slot="input-group-control"` on the element. The Textarea's classes, then the group's, as shadcn composes it. */
export function inputGroupTextareaClass(): string {
return cn(textareaClass(), 'rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent flex-1 resize-none');
}
Update the import paths to match your project setup.
Usage
import {
inputGroupAddonClass,
inputGroupButtonClass,
inputGroupClass,
inputGroupTextareaClass,
} from '#components/ui/input-group.ts';
<form action=${sendMessage}>
<input id="files" type="file" name="files" multiple tabindex="-1" class="sr-only">
<div data-slot="input-group" role="group" class=${inputGroupClass()}>
<textarea data-slot="input-group-control" name="text" aria-label="Message"
placeholder="Ask the agent to change your code..."
class=${cn(inputGroupTextareaClass(), 'p-3')}></textarea>
<div data-slot="input-group-addon" data-align="block-end" role="group" class=${inputGroupAddonClass({ align: 'block-end' })}>
<label for="files" aria-label="Attach files" data-slot="button"
class=${cn(inputGroupButtonClass({ variant: 'outline', size: 'icon-sm' }), 'rounded-full')}>
${PlusIcon()}
</label>
<button type="submit" aria-label="Send" data-slot="button"
class=${cn(inputGroupButtonClass({ variant: 'default', size: 'icon-sm' }), 'ml-auto rounded-full')}>
${ArrowUpIcon()}
</button>
</div>
</div>
</form>
The form binds a 'use server' action, so it sends with JavaScript off too. WebJs gives a bound form method="post" and enctype="multipart/form-data", so the picked files reach the action with the text.
Attachments
The attach button is a <label> for a hidden file input, so it opens the file picker with no script. Show each file as an Attachment in an addon with data-align="block-start", with a button to remove it. Reading the input's change event and rendering the chips is the component's job:
<div data-slot="input-group-addon" data-align="block-start" role="group" class=${cn(inputGroupAddonClass({ align: 'block-start' }), 'flex-wrap')}>
${files.map((file) => html`
<div data-slot="attachment" data-size="sm" class=${attachmentClass({ size: 'sm' })}>
<div data-slot="attachment-media" class=${attachmentMediaClass()}>${FileTextIcon()}</div>
<div data-slot="attachment-content" class=${attachmentContentClass()}>
<span data-slot="attachment-title" class=${attachmentTitleClass()}>${file.name}</span>
</div>
<div data-slot="attachment-actions" class=${attachmentActionsClass()}>
<button type="button" aria-label=${`Remove ${file.name}`} data-slot="attachment-action"
class=${attachmentActionClass()} @click=${() => this.remove(file)}>
${XIcon()}
</button>
</div>
</div>`)}
</div>
Model and Effort
Put the two Model Selector menus in the block-end addon, between the attach and send buttons. Move ml-auto from the send button to the first menu, so both menus sit next to the send button.
Keyboard
Enter sends the message. Shift+Enter adds a new line.
<textarea @keydown=${(event: KeyboardEvent) => {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
(event.target as HTMLTextAreaElement).form?.requestSubmit();
}
}}></textarea>
An @keydown handler runs only in a component's template, since a page does not hydrate. Render the field from your chat component, or add the listener there.
AI SDK
Send the text and the files from the form to a 'use server' action. A bound action receives the FormData, files included:
'use server';
export async function sendMessage(formData: FormData) {
const text = String(formData.get('text') ?? '');
const files = formData.getAll('files') as File[];
// ...
}
The action can stream the reply back as an async generator. See AI SDK.
Migrating from AI SDK Elements
If you used Prompt Input from AI SDK Elements, its wrapper lives in components/ai-elements/prompt-input.tsx. In a WebJs app it becomes this pattern, built from WebJs UI components. Each export of the wrapper maps onto a part:
API Reference
See Input Group and Attachment.