@@ -499,7 +499,7 @@ describe("cel end-to-end", () => {
499499 });
500500
501501 describe("onKeyPress bubbling", () => {
502- test("key bubbles from focused element up through ancestors", async () => {
502+ test("void handler consumes key — no further bubbling (backward compat)", async () => {
503503 const term = setup(20, 5);
504504 const received: string[] = [];
505505
@@ -517,6 +517,7 @@ describe("cel end-to-end", () => {
517517 {
518518 onKeyPress: (key) => {
519519 received.push("mid:" + key);
520+ // void return = consumed
520521 },
521522 },
522523 [
@@ -534,14 +535,147 @@ describe("cel end-to-end", () => {
534535 );
535536 await waitForRender();
536537
537- // Send a key — should bubble from focused btn through mid, then root
538538 term.sendInput("x");
539539 await waitForRender();
540540
541- // Nearest ancestor with onKeyPress is "mid", so it handles first
541+ // mid handler consumes (void return), root never sees the key
542542 expect(received).toEqual(["mid:x"]);
543543 });
544544
545+ test("returning false continues bubbling to parent handlers", async () => {
546+ const term = setup(20, 5);
547+ const received: string[] = [];
548+
549+ cel.viewport(() =>
550+ VStack(
551+ {
552+ width: 20,
553+ height: 5,
554+ onKeyPress: (key) => {
555+ received.push("root:" + key);
556+ },
557+ },
558+ [
559+ VStack(
560+ {
561+ onKeyPress: (key) => {
562+ received.push("mid:" + key);
563+ return false; // not consumed — keep bubbling
564+ },
565+ },
566+ [
567+ HStack(
568+ {
569+ onClick: () => {},
570+ focused: true,
571+ },
572+ [Text("Focused Btn")],
573+ ),
574+ ],
575+ ),
576+ ],
577+ ),
578+ );
579+ await waitForRender();
580+
581+ term.sendInput("x");
582+ await waitForRender();
583+
584+ // mid returns false, so key continues to root
585+ expect(received).toEqual(["mid:x", "root:x"]);
586+ });
587+
588+ test("selective bubbling — consume some keys, pass others", async () => {
589+ const term = setup(20, 5);
590+ const received: string[] = [];
591+
592+ cel.viewport(() =>
593+ VStack(
594+ {
595+ width: 20,
596+ height: 5,
597+ onKeyPress: (key) => {
598+ received.push("root:" + key);
599+ },
600+ },
601+ [
602+ VStack(
603+ {
604+ onKeyPress: (key) => {
605+ received.push("mid:" + key);
606+ // Consume "a" but pass through everything else
607+ if (key === "a") return; // consumed
608+ return false; // not consumed
609+ },
610+ },
611+ [
612+ HStack(
613+ {
614+ onClick: () => {},
615+ focused: true,
616+ },
617+ [Text("Focused Btn")],
618+ ),
619+ ],
620+ ),
621+ ],
622+ ),
623+ );
624+ await waitForRender();
625+
626+ term.sendInput("a");
627+ await waitForRender();
628+ expect(received).toEqual(["mid:a"]); // consumed by mid
629+
630+ received.length = 0;
631+ term.sendInput("b");
632+ await waitForRender();
633+ expect(received).toEqual(["mid:b", "root:b"]); // passed through to root
634+ });
635+
636+ test("all handlers return false — every handler in chain is called", async () => {
637+ const term = setup(20, 5);
638+ const received: string[] = [];
639+
640+ cel.viewport(() =>
641+ VStack(
642+ {
643+ width: 20,
644+ height: 5,
645+ onKeyPress: (key) => {
646+ received.push("root:" + key);
647+ return false;
648+ },
649+ },
650+ [
651+ VStack(
652+ {
653+ onKeyPress: (key) => {
654+ received.push("mid:" + key);
655+ return false;
656+ },
657+ },
658+ [
659+ HStack(
660+ {
661+ onClick: () => {},
662+ focused: true,
663+ },
664+ [Text("Focused Btn")],
665+ ),
666+ ],
667+ ),
668+ ],
669+ ),
670+ );
671+ await waitForRender();
672+
673+ term.sendInput("x");
674+ await waitForRender();
675+
676+ expect(received).toEqual(["mid:x", "root:x"]);
677+ });
678+
545679 test("key reaches root onKeyPress when no intermediate handlers", async () => {
546680 const term = setup(20, 5);
547681 let rootKey = "";
@@ -606,7 +740,7 @@ describe("cel end-to-end", () => {
606740 expect(parentKey).toBe("ctrl+s");
607741 });
608742
609- test("unfocused state bubbles from root only", async () => {
743+ test("unfocused state routes key to root handler", async () => {
610744 const term = setup(20, 5);
611745 let rootKey = "";
612746