xonecas.io
70160
Ce

cel-tui / commit 5e236a4

fix(core): TextInput placeholder now inherits styles from parent containers

Placeholder text nodes now participate in style inheritance. The
TextInput's resolved inherited styles (fgColor, bgColor, bold, etc.)
are merged with the placeholder's own props, with explicit placeholder
props taking priority.

Added tests: placeholder inherits styles, explicit placeholder style overrides.

xonecas2026-04-04 5e236a4b0cab7ea3062722e14cd1ba698a43034d parent 0160313

2 files changed

packages/core/src/paint.test.ts+34−0
@@ -604,6 +604,40 @@ describe("paint", () => {
604604 expect(buf.get(0, 0).char).toBe("h");
605605 expect(buf.get(0, 0).fgColor).toBe("cyan");
606606 });
607+
608+ test("TextInput placeholder inherits styles from parent container", () => {
609+ const node = VStack({ width: 10, height: 1, fgColor: "green" }, [
610+ TextInput({
611+ value: "",
612+ onChange: () => {},
613+ placeholder: Text("type..."),
614+ }),
615+ ]);
616+ const ln = layout(node, 10, 1);
617+ const buf = new CellBuffer(10, 1);
618+ paint(ln, buf);
619+
620+ // Placeholder "type..." should inherit fgColor: "green" from parent VStack
621+ expect(buf.get(0, 0).char).toBe("t");
622+ expect(buf.get(0, 0).fgColor).toBe("green");
623+ });
624+
625+ test("TextInput placeholder explicit style overrides inherited", () => {
626+ const node = VStack({ width: 10, height: 1, fgColor: "green" }, [
627+ TextInput({
628+ value: "",
629+ onChange: () => {},
630+ placeholder: Text("type...", { fgColor: "brightBlack" }),
631+ }),
632+ ]);
633+ const ln = layout(node, 10, 1);
634+ const buf = new CellBuffer(10, 1);
635+ paint(ln, buf);
636+
637+ // Explicit fgColor on placeholder should win over inherited
638+ expect(buf.get(0, 0).char).toBe("t");
639+ expect(buf.get(0, 0).fgColor).toBe("brightBlack");
640+ });
607641 });
608642
609643 describe("focusStyle", () => {
packages/core/src/paint.ts+14−3
@@ -150,7 +150,7 @@ function paintLayoutNode(
150150 italic: node.props.italic ?? tiEffective.italic,
151151 underline: node.props.underline ?? tiEffective.underline,
152152 };
153- paintTextInput(tiProps, rect, clipped, buf);
153+ paintTextInput(tiProps, rect, clipped, buf, tiEffective);
154154 break;
155155 }
156156 case "vstack":
@@ -438,6 +438,7 @@ function paintTextInput(
438438 rect: Rect,
439439 clipRect: Rect,
440440 buf: CellBuffer,
441+ inherited: StyleProps = EMPTY_STYLE,
441442 ): void {
442443 const { x, y, width: w, height: h } = rect;
443444 if (w <= 0 || h <= 0) return;
@@ -455,11 +456,21 @@ function paintTextInput(
455456 const showPlaceholder = value.length === 0 && props.placeholder;
456457
457458 if (showPlaceholder && props.placeholder) {
458- // Paint placeholder text in padded content area
459+ // Paint placeholder text in padded content area, inheriting
460+ // styles from the TextInput's resolved style chain
459461 const contentRect: Rect = { x: cx, y: cy, width: cw, height: ch };
462+ const phProps = props.placeholder.props;
463+ const effectivePh = {
464+ ...phProps,
465+ fgColor: phProps.fgColor ?? inherited.fgColor,
466+ bgColor: phProps.bgColor ?? inherited.bgColor,
467+ bold: phProps.bold ?? inherited.bold,
468+ italic: phProps.italic ?? inherited.italic,
469+ underline: phProps.underline ?? inherited.underline,
470+ };
460471 paintText(
461472 props.placeholder.content,
462- props.placeholder.props,
473+ effectivePh,
463474 contentRect,
464475 clipRect,
465476 buf,