Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ const UserInputImpl = forwardRef<UserInputHandle, UserInputProps>(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]')}
/>

<div className='flex items-center justify-between'>
Expand Down
Loading