Skip to content

Commit 5a5342e

Browse files
fix: ensure prompt input attachments render inside header (#178)
* Update prompt-input.tsx * fix: ensure prompt input attachments render inside header --------- Co-authored-by: Hayden Bleasel <hello@haydenbleasel.com>
1 parent a63d04f commit 5a5342e

File tree

7 files changed

+36
-11
lines changed

7 files changed

+36
-11
lines changed

.changeset/cute-candles-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ai-elements": patch
3+
---
4+
5+
fix: ensure prompt input attachments render inside header

apps/docs/content/docs/components/(chatbot)/prompt-input.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ import {
4040
import { GlobeIcon } from 'lucide-react';
4141

4242
<PromptInput onSubmit={() => {}} className="mt-4 relative">
43-
<PromptInputBody>
43+
<PromptInputHeader>
4444
<PromptInputAttachments>
4545
{(attachment) => (
4646
<PromptInputAttachment data={attachment} />
4747
)}
4848
</PromptInputAttachments>
49+
</PromptInputHeader>
50+
<PromptInputBody>
4951
<PromptInputTextarea onChange={(e) => {}} value={''} />
5052
</PromptInputBody>
5153
<PromptInputFooter>
@@ -189,10 +191,13 @@ const InputDemo = () => {
189191
</Conversation>
190192

191193
<PromptInput onSubmit={handleSubmit} className="mt-4" globalDrop multiple>
192-
<PromptInputBody>
194+
<PromptInputHeader>
193195
<PromptInputAttachments>
194196
{(attachment) => <PromptInputAttachment data={attachment} />}
195197
</PromptInputAttachments>
198+
</PromptInputHeader>
199+
<PromptInputBody>
200+
196201
<PromptInputTextarea
197202
onChange={(e) => setText(e.target.value)}
198203
ref={textareaRef}

apps/docs/content/docs/examples/chatbot.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ const ChatBotDemo = () => {
213213
</Conversation>
214214

215215
<PromptInput onSubmit={handleSubmit} className="mt-4" globalDrop multiple>
216-
<PromptInputBody>
216+
<PromptInputHeader>
217217
<PromptInputAttachments>
218218
{(attachment) => <PromptInputAttachment data={attachment} />}
219219
</PromptInputAttachments>
220+
</PromptInputHeader>
221+
<PromptInputBody>
220222
<PromptInputTextarea
221223
onChange={(e) => setInput(e.target.value)}
222224
value={input}

packages/elements/src/prompt-input.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,21 @@ export type PromptInputAttachmentsProps = Omit<
357357

358358
export function PromptInputAttachments({
359359
children,
360+
className,
360361
}: PromptInputAttachmentsProps) {
361362
const attachments = usePromptInputAttachments();
362363

363-
return attachments?.files.length > 0
364-
? attachments?.files.map((file) => (
364+
if (!attachments.files.length) {
365+
return null;
366+
}
367+
368+
return (
369+
<div className={cn("flex flex-wrap gap-1 p-2.5", className)}>
370+
{attachments.files.map((file) => (
365371
<Fragment key={file.id}>{children(file)}</Fragment>
366-
))
367-
: null;
372+
))}
373+
</div>
374+
);
368375
}
369376

370377
export type PromptInputActionAddAttachmentsProps = ComponentProps<

packages/examples/src/prompt-input-cursor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ const Example = () => {
230230
</div>
231231
</PromptInputHoverCardContent>
232232
</PromptInputHoverCard>
233-
</PromptInputHeader>
234-
<PromptInputBody>
235233
<PromptInputAttachments>
236234
{(attachment) => <PromptInputAttachment data={attachment} />}
237235
</PromptInputAttachments>
236+
</PromptInputHeader>
237+
<PromptInputBody>
238238
<PromptInputTextarea
239239
placeholder="Plan, search, build anything"
240240
ref={textareaRef}

packages/examples/src/prompt-input.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
PromptInputBody,
1212
PromptInputButton,
1313
PromptInputFooter,
14+
PromptInputHeader,
1415
type PromptInputMessage,
1516
PromptInputModelSelect,
1617
PromptInputModelSelectContent,
@@ -117,10 +118,12 @@ const Example = () => {
117118
<PromptInputProvider>
118119
<HeaderControls />
119120
<PromptInput globalDrop multiple onSubmit={handleSubmit}>
120-
<PromptInputBody>
121+
<PromptInputHeader>
121122
<PromptInputAttachments>
122123
{(attachment) => <PromptInputAttachment data={attachment} />}
123124
</PromptInputAttachments>
125+
</PromptInputHeader>
126+
<PromptInputBody>
124127
<PromptInputTextarea ref={textareaRef} />
125128
</PromptInputBody>
126129
<PromptInputFooter>

packages/examples/src/queue-prompt-input.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
PromptInputBody,
1212
PromptInputButton,
1313
PromptInputFooter,
14+
PromptInputHeader,
1415
type PromptInputMessage,
1516
PromptInputModelSelect,
1617
PromptInputModelSelectContent,
@@ -179,10 +180,12 @@ const Example = () => {
179180
)}
180181
</Queue>
181182
<PromptInput globalDrop multiple onSubmit={handleSubmit}>
182-
<PromptInputBody>
183+
<PromptInputHeader>
183184
<PromptInputAttachments>
184185
{(attachment) => <PromptInputAttachment data={attachment} />}
185186
</PromptInputAttachments>
187+
</PromptInputHeader>
188+
<PromptInputBody>
186189
<PromptInputTextarea
187190
onChange={(e) => setText(e.target.value)}
188191
ref={textareaRef}

0 commit comments

Comments
 (0)