Repository navigation
fix: size Input and TextArea viewports from the laid-out width - #166
Merged
Merged
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Contributor
|
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.
Owner
Author
|
@greptileai please review again |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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