diff --git a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/prompt-editor.test.tsx b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/prompt-editor.test.tsx index 5b7fc95ee03..0a69d460d47 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/prompt-editor.test.tsx +++ b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/prompt-editor.test.tsx @@ -27,6 +27,10 @@ import { usePromptEditor } from '@/app/workspace/[workspaceId]/home/components/u * stands for the scroller's content width and `contentHeight` for the height * the text wraps to at that width. Narrowing raises the content height, exactly * as rewrapping does in a browser. + * + * Scroll height is the greater of the text height and the box the element is + * pinned to, so the stub reports `contentHeight` only while the inline height + * is cleared. */ let contentHeight = 240 let editorWidth = 700 @@ -135,7 +139,7 @@ describe('PromptEditor autosize', () => { get() { if (!(this instanceof HTMLTextAreaElement)) return 0 autosizeCalls++ - return contentHeight + return Math.max(contentHeight, Number.parseFloat(this.style.height) || 0) }, }) vi.stubGlobal('ResizeObserver', FakeResizeObserver) @@ -155,6 +159,29 @@ describe('PromptEditor autosize', () => { unmount() }) + /** + * Guards the `height = 'auto'` collapse: a textarea pinned taller than its + * text reports the pinned height, so measuring without collapsing first can + * only ever grow the box. + */ + it('shrinks the textarea again when the prompt becomes shorter', () => { + const { textarea, unmount } = mountEditor() + const valueSetter = Object.getOwnPropertyDescriptor( + window.HTMLTextAreaElement.prototype, + 'value' + )?.set + if (!valueSetter) throw new Error('textarea value setter is unavailable') + + act(() => { + contentHeight = 24 + valueSetter.call(textarea, 'short') + textarea.dispatchEvent(new Event('input', { bubbles: true })) + }) + + expect(textarea.style.height).toBe('24px') + unmount() + }) + it('re-measures when the editor width changes so no text falls outside the textarea', () => { const { textarea, unmount } = mountEditor() settle() diff --git a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx index 810484c9d84..1f78a7199af 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx +++ b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx @@ -551,7 +551,7 @@ const UserInputImpl = forwardRef(function UserI placeholder='Ask Sim to ' onSubmit={handleEnterSubmit} onArrowUpOnEmpty={handleArrowUpOnEmpty} - className={isInitialView ? 'h-[56px]' : 'max-h-[200px]'} + className={cn('max-h-[200px]', isInitialView && 'min-h-[56px]')} />