Skip to content

fix: Size prompt input rows from the element's own line height and padding - #5278

Open
vvaliyev wants to merge 1 commit into
mainfrom
fix-prompt-input-sizing-js
Open

vvaliyev wants to merge 1 commit into
mainfrom
fix-prompt-input-sizing-js

Conversation

@vvaliyev

@vvaliyev vvaliyev commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Description

Replaces the token-based height formula of Prompt input with one that reads the text element's own computed line-height, padding and border, so row heights are exact and a padding change from any source (a class, :hover, :focus) is picked up through a content-box ResizeObserver. No design-token strings remain in the sizing code.

Behaviour changes (visual refresh, comfortable, minRows 1): rows are exactly rows x line-height plus padding. Defaults (maxRows 3) are unchanged at 30px empty and 70px capped. maxRows 1: 26px -> 30px (the line is no longer clipped by 4px); maxRows 2: 48px -> 50px; maxRows 4: 92px -> 90px; maxRows 10: 224px -> 210px. Visual regression will show the 4-row and 10-row pages (simple, shortcuts, container-resize).

Related links, issue #, if available: n/a

How has this been tested?

New dev page prompt-input/sizing and integration tests sizing.test.ts (floor, cap and overflow, padding class swap, hover padding, maxRows -1, token mode). All six Prompt input integration suites pass locally (53 tests); the existing maxRows 4 assertion moved from 94px to 92px (outer box). Headless Chrome measurements in visual refresh and classic, comfortable and compact, both modes. Build, unit tests, lint and tsc green.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.86%. Comparing base (645627b) to head (5906bfa).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5278   +/-   ##
=======================================
  Coverage   97.86%   97.86%           
=======================================
  Files        1016     1016           
  Lines       32847    32858   +11     
  Branches    12176    12173    -3     
=======================================
+ Hits        32146    32157   +11     
  Misses        695      695           
  Partials        6        6           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new effect can throw when ResizeObserver is unavailable and measure reference tokens before their portals commit, leaving the input too short.

2 open issues
What changed in this PR

Updates PromptInput sizing to use the element’s computed line height, padding, and borders instead of design-token formulas, aligning row limits with rendered geometry.

Changes:

  • Calculates pixel heights and observes element resizing to respond to padding changes.
  • Updates unit assertions and the existing four-row integration expectation.
  • Adds a sizing demo and integration coverage for padding overrides, hover changes, overflow, and unlimited rows.
File Description
src/​prompt-input/​internal.tsx Computes heights from element styles and adds resize observation.
src/​prompt-input/​__tests__/​prompt-input-token-mode.test.tsx Uses mocked geometry to verify pixel heights and effect triggers.
src/​prompt-input/​__integ__/​sizing.test.ts Adds browser coverage for sizing behavior in both input modes.
src/​prompt-input/​__integ__/​prompt-input.test.ts Updates the expected four-row height.
pages/​prompt-input/​sizing.scss Supplies default, large, and hover padding overrides.
pages/​prompt-input/​sizing.page.tsx Adds textarea and token-mode sizing fixtures.

Review effort: Balanced

Comment thread src/prompt-input/internal.tsx Outdated
Comment on lines +195 to +197
useEffect(() => {
if (isTokenMode) {
requestAnimationFrame(() => adjustInputHeight());
}
}, [isTokenMode, tokens, adjustInputHeight, isCompactMode, placeholder]);
adjustInputHeight();
}, [isTokenMode, tokens, adjustInputHeight, isCompactMode, placeholder, minRows, maxRows]);
Comment thread src/prompt-input/internal.tsx Resolved
@vvaliyev
vvaliyev force-pushed the fix-prompt-input-sizing-js branch from 1e7d4c6 to 031431c Compare November 11, 2026 14:18
Comment thread src/prompt-input/internal.tsx Outdated
requestAnimationFrame(() => adjustInputHeight());
}
}, [isTokenMode, tokens, adjustInputHeight, isCompactMode, placeholder]);
adjustInputHeight();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we drop the animation frame?

Comment thread src/prompt-input/internal.tsx Outdated
return;
}
}, [isTokenMode, value, adjustInputHeight, isCompactMode, placeholder, minRows, maxRows]);
const ro = new ResizeObserver(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the useResizeObserver util here?

This branch was successfully deployed

3 active deployments
dev-pages-react18 — 5906bfaf Deployed Nov 11, 2026 by vvaliyev via deploy (React 18) / deploy #3272
dev-pages-react16 — 5906bfaf Deployed Nov 11, 2026 by vvaliyev via deploy (React 16) / deploy #3272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants