@@ -278,6 +278,81 @@ describe("layout", () => {
278278 });
279279 });
280280
281+ describe("cross-axis intrinsic sizing", () => {
282+ test("HStack inside VStack uses max child height, not sum of widths", () => {
283+ // HStack with 3 Text children: each is 1 line tall.
284+ // HStack's intrinsic height should be 1 (max), not sum of widths.
285+ const node = VStack({ width: 80, height: 24 }, [
286+ HStack({}, [Text("hello"), Text("world")]),
287+ Text("below"),
288+ ]);
289+ const result = layout(node, 80, 24);
290+ const rects = childRects(result);
291+ // HStack height = 1 (tallest child is a single-line Text)
292+ expect(rects[0]!.height).toBe(1);
293+ // "below" Text starts right after
294+ expect(rects[1]!.y).toBe(1);
295+ expect(rects[1]!.height).toBe(1);
296+ });
297+
298+ test("HStack intrinsic height with multi-line text child", () => {
299+ const node = VStack({ width: 80, height: 24 }, [
300+ HStack({}, [
301+ Text("a"),
302+ Text("b\nc\nd"), // 3 lines tall
303+ ]),
304+ ]);
305+ const result = layout(node, 80, 24);
306+ // HStack height = max child height = 3
307+ expect(childRects(result)[0]!.height).toBe(3);
308+ });
309+
310+ test("VStack inside HStack uses max child width, not sum of heights", () => {
311+ const node = HStack({ width: 80, height: 24 }, [
312+ VStack({}, [VStack({ height: 3 }, []), VStack({ height: 5 }, [])]),
313+ VStack({ width: 10 }, []),
314+ ]);
315+ const result = layout(node, 80, 24);
316+ const rects = childRects(result);
317+ // First VStack intrinsic width should fill parent (80), not 3+5=8
318+ // Actually with no explicit width children, innerCross is used.
319+ // The second child starts after the first.
320+ // VStack intrinsic width = max of children's widths on cross axis
321+ // Its children have no explicit width, so they'd fill available.
322+ // Let's just check that it doesn't sum heights as width.
323+ expect(rects[0]!.width).not.toBe(8);
324+ });
325+
326+ test("hello example pattern: VStack with HStack children stacks tightly", () => {
327+ // Mimics the hello.ts layout pattern that was broken.
328+ // Key assertion: HStack children get height=1 (max child height),
329+ // not the sum of children widths.
330+ const node = VStack({ width: 80 }, [
331+ Text("logo line"),
332+ Text(""),
333+ HStack({ gap: 2 }, [Text("item1"), Text("item2"), Text("item3")]),
334+ Text(""),
335+ HStack({ gap: 1 }, [Text("a"), Text("b")]),
336+ ]);
337+ const result = layout(node, 80, 24);
338+ const rects = childRects(result);
339+ // All children should be height 1
340+ expect(rects[0]!.height).toBe(1); // Text
341+ expect(rects[1]!.height).toBe(1); // Text("")
342+ expect(rects[2]!.height).toBe(1); // HStack (was broken: summed widths)
343+ expect(rects[3]!.height).toBe(1); // Text("")
344+ expect(rects[4]!.height).toBe(1); // HStack
345+ // Children stack sequentially with no gaps
346+ expect(rects[0]!.y).toBe(0);
347+ expect(rects[1]!.y).toBe(1);
348+ expect(rects[2]!.y).toBe(2);
349+ expect(rects[3]!.y).toBe(3);
350+ expect(rects[4]!.y).toBe(4);
351+ // Total intrinsic height = 5
352+ expect(result.rect.height).toBe(5);
353+ });
354+ });
355+
281356 describe("nested layout", () => {
282357 test("editor-like layout: sidebar + main area", () => {
283358 const node = HStack({ width: 80, height: 24 }, [