AI-native design editor. Open-source Figma alternative.
Fix text w="fill" stuck at 100px in flex="col" parent
Anton A S6ff1560621a9
diff --git a/packages/core/src/layout.ts b/packages/core/src/layout.tsindex d8f0e996a..4f32cff03 100644--- a/packages/core/src/layout.ts+++ b/packages/core/src/layout.ts@@ -370,7 +370,11 @@ function configureChildAsLeaf(yogaChild: YogaNode, child: SceneNode, parent: SceyogaChild.setWidth(est.width)yogaChild.setHeight(est.height)} else if (child.textAutoResize === 'HEIGHT') {- yogaChild.setWidth(child.width)+ const stretches = child.layoutAlignSelf === 'STRETCH' ||+ (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')+ if (!(!isRow && stretches)) {+ yogaChild.setWidth(child.width)+ }yogaChild.setHeight(est.height)}} else {@@ -412,8 +416,14 @@ function configureTextLeaf(return result})} else if (autoResize === 'HEIGHT') {+ const stretchesCross = child.layoutAlignSelf === 'STRETCH' ||+ (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')+ // Don't set fixed width when text stretches on cross axis (w="fill" in+ // flex="col" parent) — setWidth blocks Yoga's alignSelf:stretch, leaving+ // text at 100px default instead of filling the parent.+ const fillsWidth = !isRow && stretchesCrossconst fixedWidth = child.width- if (child.layoutGrow <= 0) {+ if (child.layoutGrow <= 0 && !fillsWidth) {yogaChild.setWidth(fixedWidth)}yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {diff --git a/tests/engine/layout.test.ts b/tests/engine/layout.test.tsindex fdc335fcc..8a4bdc459 100644--- a/tests/engine/layout.test.ts+++ b/tests/engine/layout.test.ts@@ -1053,6 +1053,42 @@ describe('Auto Layout', () => {expect(updatedText.height).toBeGreaterThan(0)})+ test('text with w="fill" in flex="col" stretches to parent width', () => {+ const graph = new SceneGraph()+ const pid = pageId(graph)++ const frame = autoFrame(graph, pid, {+ width: 300,+ height: 400,+ layoutMode: 'VERTICAL',+ primaryAxisSizing: 'FIXED',+ counterAxisSizing: 'FIXED',+ paddingLeft: 20,+ paddingRight: 20,+ })++ const text = graph.createNode('TEXT', frame.id, {+ width: 100,+ height: 20,+ text: 'This text should fill the parent width',+ fontSize: 14,+ textAutoResize: 'HEIGHT' as const,+ layoutAlignSelf: 'STRETCH' as const,+ })++ setTextMeasurer((_node, maxWidth) => {+ const w = maxWidth ?? 260+ return { width: w, height: 20 }+ })++ computeAllLayouts(graph)+ setTextMeasurer(null)++ const updatedText = graph.getNode(text.id)!+ // Should stretch to 300 - 20 - 20 = 260, NOT stay at 100+ expect(updatedText.width).toBe(260)+ })+test('HEIGHT auto-resize text wraps via MeasureFunc when filling parent', () => {const graph = new SceneGraph()const pid = pageId(graph)