fix(native-chat): auto-grow the composer input up to 8 lines (#10848)

Reviewed with an independent reproduction. Replaced the JS measure pass with layout-native CSS on both surfaces and removed the shared hook, fixing 72-142px of Linear issue title hidden after a window resize.
This commit is contained in:
Kyle
2026-07-27 18:47:11 -07:00
committed by GitHub
parent 60c7faf930
commit 55e98e8182
3 changed files with 108 additions and 21 deletions
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef, useState } from 'react'
import React, { useCallback, useRef, useState } from 'react'
import { LoaderCircle } from 'lucide-react'
import { toast } from 'sonner'
@@ -28,21 +28,6 @@ type LinearIssueTextEditorProps = {
sourceContext?: TaskSourceContext | null
}
function useAutosizeTextArea(value: string): React.RefObject<HTMLTextAreaElement | null> {
const ref = useRef<HTMLTextAreaElement>(null)
useEffect(() => {
const textarea = ref.current
if (!textarea) {
return
}
textarea.style.height = 'auto'
textarea.style.height = `${textarea.scrollHeight}px`
}, [value])
return ref
}
export function LinearIssueTextEditor({
issue,
onIssueChange,
@@ -71,7 +56,6 @@ export function LinearIssueTextEditor({
const titleDraft = resolvedDraftState.title
const descriptionDraft = resolvedDraftState.description
const submitShortcutLabel = getScreenSubmitShortcutLabel()
const titleRef = useAutosizeTextArea(titleDraft)
const updateTitleDraft = useCallback(
(title: string): void => {
setDraftState((current) => ({
@@ -207,7 +191,6 @@ export function LinearIssueTextEditor({
{fields !== 'description' ? (
<div className="relative">
<textarea
ref={titleRef}
value={titleDraft}
onChange={(event) => updateTitleDraft(event.target.value)}
onBlur={() => void saveField('title')}
@@ -218,8 +201,11 @@ export function LinearIssueTextEditor({
'auto.components.LinearIssueTextEditor.04d73b72dc',
'Issue title'
)}
// field-sizing:content grows the title with its text and re-wraps on
// container resize without a JS measure pass.
className={cn(
'peer scrollbar-sleek block w-full resize-none overflow-hidden rounded-md border border-transparent bg-transparent px-1 py-0 text-foreground outline-none transition hover:border-border/50 hover:bg-accent/40 focus-visible:border-border focus-visible:bg-background focus-visible:ring-1 focus-visible:ring-ring disabled:opacity-80',
'[field-sizing:content]',
titleClass
)}
/>
@@ -187,10 +187,13 @@ export function NativeChatComposerField({
}
placeholder={nativeChatComposerPlaceholder(hasPty, canSend)}
// Why: coarse-pointer min-height follows the app's touch target convention.
// scrollbar-sleek keeps the overflow gutter from showing the heavy
// native scrollbar once the draft exceeds max-height.
// field-sizing:content grows the field with the draft; the 8lh cap (plus
// py-1) turns further growth into internal scrolling, and scrollbar-sleek
// keeps that gutter off the heavy native scrollbar. Both are layout-driven,
// so re-wrap on window/pane resize is handled without a measure pass.
className={cn(
'scrollbar-sleek min-h-12 max-h-28 w-full resize-none bg-transparent px-2 py-1 text-sm outline-none pointer-coarse:min-h-14',
'scrollbar-sleek min-h-12 w-full resize-none bg-transparent px-2 py-1 text-sm outline-none pointer-coarse:min-h-14',
'[field-sizing:content] max-h-[calc(8lh+0.5rem)]',
'placeholder:text-muted-foreground/60 disabled:cursor-not-allowed disabled:opacity-50'
)}
/>
@@ -0,0 +1,98 @@
// @vitest-environment happy-dom
/** The composer grows with the draft up to 8 lines, then scrolls internally.
* Sizing is layout-driven (field-sizing + an lh-relative cap) rather than a JS
* measure pass, so these assert the class contract that produces it. happy-dom
* has no layout engine, so real pixel growth is covered by app validation. */
import { createRef } from 'react'
import { cleanup, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
vi.mock('@/i18n/i18n', () => ({
translate: (_key: string, fallback: string) => fallback
}))
vi.mock('./NativeChatComposerActions', () => ({
NativeChatComposerActions: () => <div data-testid="composer-actions" />
}))
vi.mock('./NativeChatAutocompleteMenus', () => ({
NativeChatMentionHint: () => null,
NativeChatPickerMenu: () => null
}))
import { NativeChatComposerField } from './NativeChatComposerField'
afterEach(() => cleanup())
function renderField(draft: string): HTMLTextAreaElement {
render(
<NativeChatComposerField
textareaRef={createRef<HTMLTextAreaElement>()}
draft={draft}
disabled={false}
hasPty
canSend
autocomplete={{ mode: 'none' }}
activeSuggestion={0}
notice={null}
imageAttachments={[]}
sendButtonDisabled={false}
isWorking={false}
attachDisabled={false}
dictationDisabled={false}
isDictating={false}
isDictationHoldMode={false}
onDraftChange={vi.fn()}
onTextareaSelect={vi.fn()}
onKeyDown={vi.fn()}
onCompositionStart={vi.fn()}
onCompositionEnd={vi.fn()}
onPaste={vi.fn()}
pickerListboxId="picker"
onChoosePickerItem={vi.fn()}
onRetrySkills={vi.fn()}
onAcceptMention={vi.fn()}
onRemoveImageAttachment={vi.fn()}
onAttach={vi.fn()}
onDictationToggle={vi.fn()}
onDictationHoldStart={vi.fn()}
onDictationHoldEnd={vi.fn()}
onSend={vi.fn()}
sessionOptionsSurface={null}
sessionOptionsSnapshot={[]}
/>
)
return screen.getByRole('textbox') as HTMLTextAreaElement
}
describe('native chat composer autogrow', () => {
it('sizes the textarea from its content instead of staying at rows={2}', () => {
expect(renderField('').className).toContain('[field-sizing:content]')
})
it('caps growth at 8 lines plus the py-1 padding box', () => {
// 8lh tracks the rendered line-height, so the cap follows the text tokens
// instead of a hardcoded pixel value like the old max-h-28 (112px).
const textarea = renderField('a\n'.repeat(20))
expect(textarea.className).toContain('max-h-[calc(8lh+0.5rem)]')
expect(textarea.className).not.toContain('max-h-28')
})
it('keeps the sleek scrollbar for the overflow past the cap', () => {
expect(renderField('a\n'.repeat(20)).className).toContain('scrollbar-sleek')
})
it('keeps the touch-target minimum heights', () => {
const textarea = renderField('')
expect(textarea.className).toContain('min-h-12')
expect(textarea.className).toContain('pointer-coarse:min-h-14')
})
it('does not pin an inline height that a resize could leave stale', () => {
// A JS measure pass writes style.height and only re-measures on the next
// value change, so a re-wrap from a window/pane resize would strand it.
expect(renderField('a\n'.repeat(6)).style.height).toBe('')
})
})