Skip to content

fix: size Input and TextArea viewports from the laid-out width - #166

Merged
grindlemire merged 3 commits into
mainfrom
fix/input-viewport-size
Sep 16, 2026
Merged

grindlemire merged 3 commits into
mainfrom
fix/input-viewport-size

Conversation

@grindlemire

@grindlemire grindlemire commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Input scrolled inside its configured width and TextArea wrapped at its configured width even when a class like w-full, w-1/2, or flex-1 gave the root element a different width, so the text used a fraction of the box.

Both components now record the content width the layout engine assigns their root, through a small onLayout hook the render walk fires once per frame with the final box (after a scrollable parent's scrollbar re-layout), and slice or wrap for that width. A frame laid out at a width the component did not render for marks the app dirty, so the next frame renders at the assigned width; the input takes one more frame when pulling its scroll back writes state. Before the first layout the configured width still applies, and a laid-out width of zero is honored rather than treated as unset. A TextArea whose root width is not fixed leaves its height auto and installs a measure hook that HeightForWidth consults, so the engine sizes the box from the rows the text needs at the width it assigns, in the same pass. With an auto width the configured width becomes a minimum, because the box would otherwise size to the sliced text and pin the viewport there. The input also pulls its scroll back when the viewport grows so hidden text comes back into view.

The two Element hooks are unexported for now, so the public API is unchanged; exporting them for custom components can be a follow-up. The rows a textarea renders still come from the previous frame's width, so a width change shows the old rows for one frame before the settle frame corrects them. The column branch of HeightForWidth keeps measuring children at the full content width, so a w-1/2 textarea nested in a column that a row parent measures is still estimated at the full width, as wrapped text already is. An explicit w-auto beside a grow factor in a row sizes the flex basis from the previous frame's text, so the box grows over a few frames; the styling guide points row fills at flex-1 alone.

Fixes #158

The Input scrolled inside its configured width and the TextArea wrapped
at its configured width even when a class such as w-full, w-1/2, or
flex-1 gave the root element another width, so the text ignored most of
the box.

Both components now record the content width the layout engine assigns
their root, through an onLayout hook fired from Element.SetLayout, and
slice or wrap for that width. A frame laid out at a width the component
did not render for marks the app dirty, so the next frame settles at the
assigned width; before the first layout the configured width applies. A
TextArea whose root width is not fixed leaves its height auto and
installs a measure hook that HeightForWidth consults, so the engine
sizes the box from the rows the text needs at the width it assigns in
the same pass. With an auto width the configured width becomes a
minimum, since the box would otherwise size to the sliced text and pin
the viewport there. The input also pulls its scroll back when the
viewport grows so hidden text reappears.

Fixes #158
@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.01493% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.74%. Comparing base (bf66969) to head (e7f4194).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
textarea.go 93.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #166      +/-   ##
==========================================
+ Coverage   84.68%   84.74%   +0.05%     
==========================================
  Files         169      169              
  Lines       21534    21588      +54     
==========================================
+ Hits        18237    18295      +58     
+ Misses       2635     2633       -2     
+ Partials      662      660       -2     

☔ 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.

@greptile-apps

greptile-apps Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the earlier zero-width settling issue is fixed and no new actionable failures remain.

Summary

This PR makes Input viewports and TextArea wrapping follow their final laid-out content width.

  • Adds internal measurement and post-layout hooks for width-dependent components.
  • Preserves zero as a valid laid-out width and settles scroll-container re-layouts.
  • Reclaims Input scroll slack after viewport growth or text shrinkage.
  • Measures auto-height TextAreas using their assigned content width.
  • Adds regression coverage and updates component and styling documentation.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Render Input or TextArea] --> B[Use last laid-out width]
    B --> C[Layout computes final box]
    C --> D[Render walk reports final content width]
    D --> E{Width changed?}
    E -- Yes --> F[Mark application dirty]
    F --> A
    E -- No --> G[Viewport and layout settled]
Loading

Reviews (2) · Last reviewed commit: "fix: settle Input and TextArea inside sc..."

Comment thread input.go Resolved
The onLayout hook now fires from the render walk (renderElement and
renderClippedElement) instead of SetLayout, so a scrollable parent's
measure-then-gutter layout passes no longer mark the app dirty every
frame. A laidOut flag separates "not laid out yet" from a real zero
width, so a fully shrunk flex item settles instead of falling back to
the configured width each frame. The clampScroll comment now describes
the unfocused path correctly, and the styling guide steers row fills to
flex-1 alone since w-auto beside a grow factor sizes from the previous
frame's text.
@grindlemire

Copy link
Copy Markdown
Owner Author

@greptileai please review again

@grindlemire
grindlemire merged commit 4c7b128 into main Sep 16, 2026
7 checks passed
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.

Input and TextArea only size their viewport from a fixed width

1 participant