Skip to content

Commit d370714

Browse files
committed
fix(search): expand composer around image attachments
1 parent 8e78a7b commit d370714

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

‎apps/sim/app/o/[organizationId]/components/search-input-bar.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface SearchInputBarProps {
2121
placeholder?: string
2222
'aria-label'?: string
2323
leadingControls?: ReactNode
24+
attachments?: ReactNode
2425
selectionControl?: ReactNode
2526
voiceControl?: ReactNode
2627
submitControl: ReactNode
@@ -30,6 +31,7 @@ interface SearchInputBarProps {
3031
/** Canonical Search bar shared by raw search and conversational Search. */
3132
export function SearchInputBar({
3233
leadingControls,
34+
attachments,
3335
inputRef,
3436
value,
3537
onChange,
@@ -47,6 +49,7 @@ export function SearchInputBar({
4749
const trailingRef = useRef<HTMLDivElement>(null)
4850
const textMeasureRef = useRef<HTMLSpanElement>(null)
4951
const [expanded, setExpanded] = useState(value.includes('\n'))
52+
const hasAttachments = Boolean(attachments)
5053

5154
/** Measure against the compact width so expanding the field cannot cause a wrap/collapse loop. */
5255
useLayoutEffect(() => {
@@ -72,16 +75,18 @@ export function SearchInputBar({
7275
const observer = new ResizeObserver(measure)
7376
for (const element of [bar, leading, trailing]) observer.observe(element)
7477
return () => observer.disconnect()
75-
}, [value])
78+
}, [value, hasAttachments])
7679

7780
return (
7881
<div
7982
ref={scrollerRef}
8083
className={cn(
8184
'relative min-h-[46px] w-full rounded-[23px] border border-[var(--border-1)] bg-[var(--white)] py-[7px] pr-2.5 pl-4 dark:bg-[var(--surface-4)]',
85+
hasAttachments && 'rounded-2xl px-2.5 py-2',
8286
floating && 'shadow-ambient'
8387
)}
8488
>
89+
{attachments}
8590
<InputToolbar
8691
leadingRef={leadingRef}
8792
trailingRef={trailingRef}
@@ -92,13 +97,14 @@ export function SearchInputBar({
9297
selectionControl={selectionControl}
9398
voiceControl={voiceControl}
9499
submitControl={submitControl}
95-
expanded={expanded}
100+
expanded={hasAttachments || expanded}
96101
editor={
97102
<GrowingTextarea
98103
inputRef={inputRef}
99104
scrollerRef={scrollerRef}
100105
value={value}
101-
compact={!expanded}
106+
compact={!hasAttachments && !expanded}
107+
className={hasAttachments ? 'min-h-[56px]' : undefined}
102108
maxHeight={200}
103109
onChange={(event) => onChange(event.target.value)}
104110
onKeyDown={(event) => {

‎apps/sim/app/o/[organizationId]/home/components/composer/composer.test.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ describe('organization image composer', () => {
321321
})
322322
)
323323
expect(container.querySelector('img')?.getAttribute('alt')).toBe('screenshot.png')
324+
const searchBar = container
325+
.querySelector<HTMLTextAreaElement>('[aria-label="Ask Sim"]')!
326+
.closest('div.rounded-2xl')
327+
expect(searchBar?.contains(container.querySelector('img'))).toBe(true)
328+
expect(searchBar?.querySelector('textarea')?.className).toContain('min-h-[56px]')
324329
await act(async () =>
325330
container.querySelector<HTMLButtonElement>('button[aria-label="Send"]')!.click()
326331
)

‎apps/sim/app/o/[organizationId]/home/components/composer/composer.tsx‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ export function Composer({
285285
</ComposerActionButton>
286286
)
287287

288+
const attachmentList = files.attachedFiles.length ? (
289+
<AttachedFilesList
290+
attachedFiles={files.attachedFiles}
291+
onFileClick={files.handleFileClick}
292+
onRemoveFile={files.removeFile}
293+
/>
294+
) : null
295+
288296
return (
289297
<div
290298
onDragEnter={files.handleDragEnter}
@@ -298,16 +306,13 @@ export function Composer({
298306
!imagesOnly && isInitialView && 'shadow-ambient'
299307
)}
300308
>
301-
<AttachedFilesList
302-
attachedFiles={files.attachedFiles}
303-
onFileClick={files.handleFileClick}
304-
onRemoveFile={files.removeFile}
305-
/>
309+
{!imagesOnly && attachmentList}
306310
{!imagesOnly && promptEditor}
307311

308312
{imagesOnly ? (
309313
<SearchInputBar
310314
floating={isInitialView}
315+
attachments={attachmentList}
311316
inputRef={textareaRef}
312317
value={editor.value}
313318
onChange={(text) => editor.setValue(text)}

0 commit comments

Comments
 (0)