Prompt Input
nexus-ui/prompt-inputFreeComponent
Composable chat input with auto-resizing textarea and action slots
Live preview
live · rendered by the registry
Rendered by nexus-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://nexus-ui.dev/r/prompt-input.jsonSource
1"use client";23import * as React from "react";4import { Slot } from "@radix-ui/react-slot";56import { mergeRefs } from "@/lib/merge-refs";7import { cn } from "@/lib/utils";8import { Textarea } from "@/components/ui/textarea";9import { ScrollArea, ScrollViewport } from "@/components/ui/scroll-area";10import {11 Tooltip,12 TooltipContent,13 TooltipProvider,14 TooltipTrigger,15} from "@/components/ui/tooltip";16import { Kbd } from "@/components/ui/kbd";1718type PromptInputContextValue = {19 setTextareaNode: (node: HTMLTextAreaElement | null) => void;20 onSubmit?: (value: string) => void;21};2223const PromptInputContext = React.createContext<PromptInputContextValue | null>(24 null,25);2627type PromptInputProps = Omit<28 React.HTMLAttributes<HTMLDivElement>,29 "onSubmit"30> & {31 /**32 * Called when Enter is pressed in the textarea (without Shift). Use with33 * value/onChange on PromptInputTextarea for controlled mode. Shift+Enter34 * inserts a new line.35 */36 onSubmit?: (value: string) => void;37};3839function PromptInput({40 className,41 role: _role,42 "aria-label": _ariaLabel,43 onClick,44 onSubmit,45 ...props46}: PromptInputProps) {47 const textareaRef = React.useRef<HTMLTextAreaElement | null>(null);4849 const handleClick = React.useCallback(50 (e: React.MouseEvent<HTMLDivElement>) => {51 const target = e.target as HTMLElement;52 if (53 !target.closest(54 'button, a, input, textarea, [role="button"], [role="tab"]',55 )56 ) {57 textareaRef.current?.focus();58 }59 onClick?.(e);60 },61 [onClick],62 );6364 const contextValue = React.useMemo<PromptInputContextValue>(65 () => ({66 setTextareaNode: (node) => {67 textareaRef.current = node;68 },69 onSubmit,70 }),71 [onSubmit],72 );7374 return (75 <TooltipProvider delayDuration={100}>76 <PromptInputContext.Provider value={contextValue}>77 <div78 role="group"79 aria-label="Chat input"80 className={cn(81 "relative flex h-auto w-full cursor-text flex-col gap-0 overflow-hidden rounded-3xl border border-border bg-card dark:border-border/50 dark:bg-input/30",82 className,83 )}84 onClick={handleClick}85 {...props}86 />87 </PromptInputContext.Provider>88 </TooltipProvider>89 );90}9192type PromptInputTextareaProps = React.ComponentProps<typeof Textarea>;9394const PromptInputTextarea = React.forwardRef<95 HTMLTextAreaElement,96 PromptInputTextareaProps97// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from nexus-ui
All 15 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Attachmentsattachments | nexus-ui | Components | Free | 4 deps · 2 files | |
| Chain of Thoughtchain-of-thought | nexus-ui | Components | Free | 2 deps · 2 files | |
| Citationcitation | nexus-ui | Components | Free | 4 deps | |
| Feedback Barfeedback-bar | nexus-ui | Components | Free | 1 dep | |
| Imageimage | nexus-ui | Components | Free | 2 deps | |
| Messagemessage | nexus-ui | Components | Free | 9 deps · 2 files | |
| Model Selectormodel-selector | nexus-ui | Components | Free | 3 deps | |
| Questionsquestions | nexus-ui | Components | Free | 2 deps |
