xonecas.io
70160
Ce

cel-tui / commit 0c44ffa

feat(components): add Select component inspired by yoctoselect

Filterable select list with keyboard navigation. Factory function
returns a callable SelectInstance — call it inside cel.viewport()
to produce the current node tree. Internal state (query, highlight,
scroll) is managed in the closure.

Keyboard: type to filter, ↑/↓ to navigate (wraps), Enter to select,
Home/End to jump, Backspace to delete. Unhandled keys forward to
onKeyPress callback for app-level shortcuts.

Mouse: click any item to select it (items have onClick + focusable:
false so they don't interfere with Tab order).

Includes:
- normalizeItems, prefixFilter (prefix + word-boundary matching)
- moveUp/moveDown with wrapping, adjustScroll viewport management
- .reset() to clear query/highlight/scroll
- Full container prop forwarding (width, height, flex, colors, etc.)
- focusStyle support for visual focus feedback
- 23 tests (pure logic + component integration)
- Interactive example (examples/select.ts)

Also fixes a core bug: containers with explicit focusable: true but
no onClick were not included in focus traversal. Updated
collectFocusable and findClickFocusTarget to support this.

xonecas2026-04-04 0c44ffa2ffbeac6e4e6975de377d6c56c882d88a parent 6a47e37

7 files changed

examples/select.ts+90−0
@@ -0,0 +1,90 @@
1+import { cel, VStack, HStack, Text, ProcessTerminal } from "@cel-tui/core";
2+import { Select, Divider, Spacer } from "@cel-tui/components";
3+
4+let selected = "";
5+
6+const fruits = [
7+ "apple",
8+ "apricot",
9+ "avocado",
10+ "banana",
11+ "blackberry",
12+ "blueberry",
13+ "cherry",
14+ "coconut",
15+ "cranberry",
16+ "date",
17+ "dragonfruit",
18+ "elderberry",
19+ "fig",
20+ "grape",
21+ "guava",
22+ "kiwi",
23+ "lemon",
24+ "lime",
25+ "lychee",
26+ "mango",
27+ "nectarine",
28+ "orange",
29+ "papaya",
30+ "peach",
31+ "pear",
32+ "pineapple",
33+ "plum",
34+ "pomegranate",
35+ "raspberry",
36+ "strawberry",
37+ "watermelon",
38+];
39+
40+const fruitSelect = Select({
41+ items: fruits,
42+ maxVisible: 8,
43+ placeholder: "search fruits...",
44+ onSelect: (value) => {
45+ selected = value;
46+ cel.render();
47+ },
48+ onKeyPress: (key) => {
49+ if (key === "ctrl+q") {
50+ cel.stop();
51+ process.exit();
52+ }
53+ if (key === "ctrl+r") {
54+ selected = "";
55+ fruitSelect.reset();
56+ cel.render();
57+ }
58+ },
59+ focusStyle: { fgColor: "white" },
60+});
61+
62+cel.init(new ProcessTerminal());
63+cel.viewport(() =>
64+ VStack(
65+ {
66+ height: "100%",
67+ padding: { x: 2, y: 1 },
68+ fgColor: "white",
69+ },
70+ [
71+ Text("Select Component Demo", { bold: true, fgColor: "cyan" }),
72+ Text("Tab to focus · type to filter · ↑↓ to navigate · Enter to select", {
73+ fgColor: "brightBlack",
74+ }),
75+ Divider({ fgColor: "brightBlack" }),
76+ Text(""),
77+ fruitSelect(),
78+ Text(""),
79+ Divider({ fgColor: "brightBlack" }),
80+ selected
81+ ? HStack({}, [
82+ Text("Selected: ", { fgColor: "brightBlack" }),
83+ Text(selected, { bold: true, fgColor: "green" }),
84+ ])
85+ : Text("No selection yet", { fgColor: "brightBlack" }),
86+ Spacer(),
87+ Text("Ctrl+R reset · Ctrl+Q quit", { fgColor: "brightBlack" }),
88+ ],
89+ ),
90+);
packages/components/src/index.ts+7−1
@@ -6,7 +6,7 @@
66 *
77 * @example
88 * ```ts
9- * import { Spacer, Divider, Button } from "@cel-tui/components";
9+ * import { Spacer, Divider, Button, Select } from "@cel-tui/components";
1010 *
1111 * HStack({ height: 1 }, [
1212 * Text("Title", { bold: true }),
@@ -19,3 +19,9 @@
1919 export { Spacer } from "./spacer.js";
2020 export { Divider, type DividerProps } from "./divider.js";
2121 export { Button, type ButtonProps } from "./button.js";
22+export {
23+ Select,
24+ type SelectProps,
25+ type SelectItem,
26+ type SelectInstance,
27+} from "./select.js";
packages/components/src/select.test.ts+200−0
@@ -0,0 +1,200 @@
1+import { describe, it, expect } from "bun:test";
2+import {
3+ normalizeItems,
4+ prefixFilter,
5+ moveUp,
6+ moveDown,
7+ adjustScroll,
8+ Select,
9+} from "./select.js";
10+import type { NormalizedItem } from "./select.js";
11+
12+describe("normalizeItems", () => {
13+ it("normalizes string items", () => {
14+ const result = normalizeItems(["apple", "banana"]);
15+ expect(result).toEqual([
16+ { label: "apple", value: "apple", filterText: "apple" },
17+ { label: "banana", value: "banana", filterText: "banana" },
18+ ]);
19+ });
20+
21+ it("normalizes object items with filterText", () => {
22+ const result = normalizeItems([
23+ { label: "Apple (red)", value: "apple", filterText: "apple" },
24+ ]);
25+ expect(result).toEqual([
26+ { label: "Apple (red)", value: "apple", filterText: "apple" },
27+ ]);
28+ });
29+
30+ it("defaults filterText to label", () => {
31+ const result = normalizeItems([{ label: "Apple", value: "apple" }]);
32+ expect(result).toEqual([
33+ { label: "Apple", value: "apple", filterText: "Apple" },
34+ ]);
35+ });
36+});
37+
38+describe("prefixFilter", () => {
39+ const items: NormalizedItem[] = [
40+ { label: "apple", value: "apple", filterText: "apple" },
41+ { label: "banana", value: "banana", filterText: "banana" },
42+ { label: "cherry", value: "cherry", filterText: "cherry" },
43+ { label: "avocado", value: "avocado", filterText: "avocado" },
44+ ];
45+
46+ it("returns all items for empty query", () => {
47+ expect(prefixFilter(items, "")).toEqual(items);
48+ });
49+
50+ it("filters by prefix", () => {
51+ const result = prefixFilter(items, "a");
52+ expect(result).toEqual([
53+ { label: "apple", value: "apple", filterText: "apple" },
54+ { label: "avocado", value: "avocado", filterText: "avocado" },
55+ ]);
56+ });
57+
58+ it("is case-insensitive", () => {
59+ const result = prefixFilter(items, "A");
60+ expect(result.length).toBe(2);
61+ });
62+
63+ it("matches word boundaries", () => {
64+ const paths: NormalizedItem[] = [
65+ {
66+ label: "src/components/button.ts",
67+ value: "button",
68+ filterText: "src/components/button.ts",
69+ },
70+ ];
71+ const result = prefixFilter(paths, "button");
72+ expect(result.length).toBe(1);
73+ });
74+
75+ it("returns empty for no matches", () => {
76+ const result = prefixFilter(items, "xyz");
77+ expect(result).toEqual([]);
78+ });
79+});
80+
81+describe("moveUp", () => {
82+ it("moves up by one", () => {
83+ expect(moveUp(2, 5)).toBe(1);
84+ });
85+
86+ it("wraps from first to last", () => {
87+ expect(moveUp(0, 5)).toBe(4);
88+ });
89+
90+ it("returns 0 for empty list", () => {
91+ expect(moveUp(0, 0)).toBe(0);
92+ });
93+});
94+
95+describe("moveDown", () => {
96+ it("moves down by one", () => {
97+ expect(moveDown(2, 5)).toBe(3);
98+ });
99+
100+ it("wraps from last to first", () => {
101+ expect(moveDown(4, 5)).toBe(0);
102+ });
103+
104+ it("returns 0 for empty list", () => {
105+ expect(moveDown(0, 0)).toBe(0);
106+ });
107+});
108+
109+describe("adjustScroll", () => {
110+ it("keeps scroll when highlight is visible", () => {
111+ expect(adjustScroll(3, 0, 5)).toBe(0);
112+ });
113+
114+ it("scrolls up when highlight is above viewport", () => {
115+ expect(adjustScroll(1, 3, 5)).toBe(1);
116+ });
117+
118+ it("scrolls down when highlight is below viewport", () => {
119+ expect(adjustScroll(7, 0, 5)).toBe(3);
120+ });
121+});
122+
123+describe("Select", () => {
124+ it("returns a callable render function", () => {
125+ const select = Select({
126+ items: ["apple", "banana"],
127+ onSelect: () => {},
128+ });
129+ const node = select();
130+ expect(node.type).toBe("vstack");
131+ expect(node.children.length).toBeGreaterThan(0);
132+ });
133+
134+ it("renders search line and items", () => {
135+ const select = Select({
136+ items: ["apple", "banana", "cherry"],
137+ onSelect: () => {},
138+ });
139+ const node = select();
140+ // Search line + 3 items = 4 children
141+ expect(node.children.length).toBe(4);
142+ });
143+
144+ it("shows overflow indicator when items exceed maxVisible", () => {
145+ const items = Array.from({ length: 15 }, (_, i) => `item-${i}`);
146+ const select = Select({
147+ items,
148+ onSelect: () => {},
149+ maxVisible: 5,
150+ });
151+ const node = select();
152+ // Search line + 5 visible items + overflow indicator = 7
153+ expect(node.children.length).toBe(7);
154+ // Last child should contain overflow text
155+ const lastChild = node.children[6]!;
156+ expect(lastChild.type).toBe("hstack");
157+ if (lastChild.type === "hstack") {
158+ const text = lastChild.children[0];
159+ expect(text).toBeDefined();
160+ if (text?.type === "text") {
161+ expect(text.content).toContain("10 more");
162+ }
163+ }
164+ });
165+
166+ it("has reset method that clears state", () => {
167+ const select = Select({
168+ items: ["apple", "banana"],
169+ onSelect: () => {},
170+ });
171+ // reset exists and is callable
172+ expect(typeof select.reset).toBe("function");
173+ select.reset(); // should not throw
174+ });
175+
176+ it("sets focusable true by default", () => {
177+ const select = Select({
178+ items: ["apple"],
179+ onSelect: () => {},
180+ });
181+ const node = select();
182+ expect(node.props.focusable).toBe(true);
183+ });
184+
185+ it("forwards container props", () => {
186+ const select = Select({
187+ items: ["apple"],
188+ onSelect: () => {},
189+ width: 30,
190+ fgColor: "green",
191+ bgColor: "black",
192+ flex: 1,
193+ });
194+ const node = select();
195+ expect(node.props.width).toBe(30);
196+ expect(node.props.fgColor).toBe("green");
197+ expect(node.props.bgColor).toBe("black");
198+ expect(node.props.flex).toBe(1);
199+ });
200+});
packages/components/src/select.ts+401−0
@@ -0,0 +1,401 @@
1+import type {
2+ Color,
3+ ContainerNode,
4+ Node,
5+ SizeValue,
6+ StyleProps,
7+} from "@cel-tui/types";
8+import { cel, VStack, HStack, Text } from "@cel-tui/core";
9+
10+/**
11+ * An item in the select list.
12+ *
13+ * Strings are used as both label and value. Objects allow separate
14+ * display text, return value, and filter text.
15+ *
16+ * @example
17+ * // Simple string item
18+ * "apple"
19+ *
20+ * // Rich item with ANSI-colored label
21+ * { label: "claude-sonnet-4 (free)", value: "anthropic/claude-sonnet-4", filterText: "claude-sonnet-4" }
22+ */
23+export type SelectItem =
24+ | string
25+ | {
26+ /** Displayed text (can include ANSI styling). */
27+ label: string;
28+ /** Value returned on selection. */
29+ value: string;
30+ /** Text matched against the search query. Defaults to `label`. */
31+ filterText?: string;
32+ };
33+
34+/** Configuration for the {@link Select} component. */
35+export interface SelectProps {
36+ /** Items to choose from. */
37+ items: SelectItem[];
38+ /**
39+ * Called when the user selects an item (Enter or click).
40+ * @param value - The selected item's value.
41+ */
42+ onSelect: (value: string) => void;
43+ /**
44+ * Placeholder text shown when the search query is empty.
45+ * @default "type to filter..."
46+ */
47+ placeholder?: string;
48+ /**
49+ * Maximum number of items visible at once.
50+ * When the filtered list exceeds this, a "N more" indicator is shown.
51+ * @default 10
52+ */
53+ maxVisible?: number;
54+ /**
55+ * Character used for the highlight indicator.
56+ * @default "›"
57+ */
58+ indicator?: string;
59+ /**
60+ * Color of the highlighted item and its indicator.
61+ * @default "cyan"
62+ */
63+ highlightColor?: Color;
64+ /**
65+ * Called for key events not consumed by the Select
66+ * (e.g., modifier combos like `"ctrl+s"`).
67+ * Use this to handle application-level shortcuts when the Select is focused.
68+ *
69+ * @param key - The unhandled key string.
70+ */
71+ onKeyPress?: (key: string) => void;
72+ /** Fixed width in cells or percentage. */
73+ width?: SizeValue;
74+ /** Fixed height in cells or percentage. */
75+ height?: SizeValue;
76+ /** Flex grow factor. */
77+ flex?: number;
78+ /** Foreground text color. */
79+ fgColor?: Color;
80+ /** Background color (fills the container rect). */
81+ bgColor?: Color;
82+ /**
83+ * Whether the select is currently focused (controlled mode).
84+ * When omitted, focus is uncontrolled (framework-managed).
85+ */
86+ focused?: boolean;
87+ /**
88+ * Whether the select participates in focus traversal.
89+ * @default true
90+ */
91+ focusable?: boolean;
92+ /** Called when the select receives focus. */
93+ onFocus?: () => void;
94+ /** Called when the select loses focus. */
95+ onBlur?: () => void;
96+ /** Style overrides applied when focused. */
97+ focusStyle?: StyleProps;
98+}
99+
100+/**
101+ * A Select component instance returned by {@link Select}.
102+ *
103+ * Call it to get the current Node tree for rendering.
104+ * Use `.reset()` to clear the search query and highlight.
105+ */
106+export interface SelectInstance {
107+ /** Returns the current Select node tree. Call inside `cel.viewport()`. */
108+ (): ContainerNode;
109+ /** Reset the search query, highlight position, and scroll offset. */
110+ reset(): void;
111+}
112+
113+/** Normalized form of a SelectItem with all fields resolved. */
114+export interface NormalizedItem {
115+ label: string;
116+ value: string;
117+ filterText: string;
118+}
119+
120+/**
121+ * Normalize SelectItem inputs into a consistent shape.
122+ * Strings become `{ label: s, value: s, filterText: s }`.
123+ */
124+export function normalizeItems(items: SelectItem[]): NormalizedItem[] {
125+ return items.map((item) => {
126+ if (typeof item === "string") {
127+ return { label: item, value: item, filterText: item };
128+ }
129+ return {
130+ label: item.label,
131+ value: item.value,
132+ filterText: item.filterText ?? item.label,
133+ };
134+ });
135+}
136+
137+/**
138+ * Filter items by prefix match against filterText.
139+ * Matches the start of the full text or any whitespace/slash-separated word.
140+ */
141+export function prefixFilter(
142+ items: NormalizedItem[],
143+ query: string,
144+): NormalizedItem[] {
145+ if (!query) return items;
146+ const q = query.toLowerCase();
147+ return items.filter((item) => {
148+ const text = item.filterText.toLowerCase();
149+ if (text.startsWith(q)) return true;
150+ const words = text.split(/[\s/]+/);
151+ return words.some((word) => word.startsWith(q));
152+ });
153+}
154+
155+/** Move highlight up with wrapping. */
156+export function moveUp(highlight: number, total: number): number {
157+ if (total === 0) return 0;
158+ return highlight <= 0 ? total - 1 : highlight - 1;
159+}
160+
161+/** Move highlight down with wrapping. */
162+export function moveDown(highlight: number, total: number): number {
163+ if (total === 0) return 0;
164+ return highlight >= total - 1 ? 0 : highlight + 1;
165+}
166+
167+/** Adjust scroll offset to keep the highlighted item visible. */
168+export function adjustScroll(
169+ highlight: number,
170+ scrollOffset: number,
171+ maxVisible: number,
172+): number {
173+ if (highlight < scrollOffset) return highlight;
174+ if (highlight >= scrollOffset + maxVisible) return highlight - maxVisible + 1;
175+ return scrollOffset;
176+}
177+
178+/**
179+ * Creates a filterable select list component.
180+ *
181+ * Returns a {@link SelectInstance} — call it inside `cel.viewport()` to
182+ * produce the current Node tree. Internal state (search query, highlight
183+ * position, scroll offset) is managed automatically. Keyboard navigation
184+ * works when the component is focused (Tab into it or click an item).
185+ *
186+ * **Keyboard:**
187+ * | Key | Action |
188+ * |-------------|-------------------------------------|
189+ * | Type | Filter items by prefix |
190+ * | `↑` / `↓` | Move highlight (wraps around) |
191+ * | `Enter` | Select highlighted item |
192+ * | `Escape` | Unfocus (framework default) |
193+ * | `Home`/`End`| Jump to first/last |
194+ * | `Backspace` | Delete last filter character |
195+ *
196+ * @param props - Select configuration and items.
197+ * @returns A callable instance that produces the Select node tree.
198+ *
199+ * @example
200+ * ```ts
201+ * import { cel, VStack, Text, ProcessTerminal } from "@cel-tui/core";
202+ * import { Select } from "@cel-tui/components";
203+ *
204+ * let selected = "";
205+ *
206+ * const fruitSelect = Select({
207+ * items: ["apple", "banana", "cherry", "date", "elderberry"],
208+ * onSelect: (value) => {
209+ * selected = value;
210+ * cel.render();
211+ * },
212+ * });
213+ *
214+ * cel.init(new ProcessTerminal());
215+ * cel.viewport(() =>
216+ * VStack({ height: "100%" }, [
217+ * Text(`Selected: ${selected}`),
218+ * fruitSelect(),
219+ * ]),
220+ * );
221+ * ```
222+ */
223+export function Select(props: SelectProps): SelectInstance {
224+ const {
225+ items: rawItems,
226+ onSelect,
227+ placeholder = "type to filter...",
228+ maxVisible = 10,
229+ indicator = "›",
230+ highlightColor = "cyan",
231+ onKeyPress: userKeyPress,
232+ width,
233+ height,
234+ flex,
235+ fgColor,
236+ bgColor,
237+ focused,
238+ focusable,
239+ onFocus,
240+ onBlur,
241+ focusStyle,
242+ } = props;
243+
244+ let query = "";
245+ let highlightIndex = 0;
246+ let scrollOffset = 0;
247+
248+ function getFiltered(): NormalizedItem[] {
249+ return prefixFilter(normalizeItems(rawItems), query);
250+ }
251+
252+ function handleKey(key: string): void {
253+ switch (key) {
254+ case "enter": {
255+ const filtered = getFiltered();
256+ const selected = filtered[highlightIndex];
257+ if (selected) onSelect(selected.value);
258+ return;
259+ }
260+
261+ case "backspace":
262+ if (query.length > 0) {
263+ query = query.slice(0, -1);
264+ highlightIndex = 0;
265+ scrollOffset = 0;
266+ cel.render();
267+ }
268+ return;
269+
270+ case "up": {
271+ const filtered = getFiltered();
272+ highlightIndex = moveUp(highlightIndex, filtered.length);
273+ scrollOffset = adjustScroll(highlightIndex, scrollOffset, maxVisible);
274+ cel.render();
275+ return;
276+ }
277+
278+ case "down": {
279+ const filtered = getFiltered();
280+ highlightIndex = moveDown(highlightIndex, filtered.length);
281+ scrollOffset = adjustScroll(highlightIndex, scrollOffset, maxVisible);
282+ cel.render();
283+ return;
284+ }
285+
286+ case "home":
287+ highlightIndex = 0;
288+ scrollOffset = 0;
289+ cel.render();
290+ return;
291+
292+ case "end": {
293+ const filtered = getFiltered();
294+ highlightIndex = Math.max(0, filtered.length - 1);
295+ scrollOffset = adjustScroll(highlightIndex, scrollOffset, maxVisible);
296+ cel.render();
297+ return;
298+ }
299+
300+ default:
301+ // Single printable character — append to query
302+ if (key.length === 1 && key >= " ") {
303+ query += key;
304+ highlightIndex = 0;
305+ scrollOffset = 0;
306+ cel.render();
307+ } else {
308+ // Forward unrecognized keys to user callback
309+ userKeyPress?.(key);
310+ }
311+ return;
312+ }
313+ }
314+
315+ function render(): ContainerNode {
316+ const allItems = normalizeItems(rawItems);
317+ const filtered = prefixFilter(allItems, query);
318+ const visible = filtered.slice(scrollOffset, scrollOffset + maxVisible);
319+ const overflow = filtered.length - scrollOffset - visible.length;
320+
321+ const children: Node[] = [];
322+
323+ // Search line
324+ const searchContent = query
325+ ? Text(query)
326+ : Text(placeholder, { fgColor: "brightBlack" });
327+ children.push(
328+ HStack({}, [Text("search: ", { fgColor: "brightBlack" }), searchContent]),
329+ );
330+
331+ // Items
332+ if (filtered.length === 0) {
333+ children.push(
334+ HStack({}, [Text(" no matches", { fgColor: "brightBlack" })]),
335+ );
336+ } else {
337+ for (let i = 0; i < visible.length; i++) {
338+ const item = visible[i]!;
339+ const globalIndex = scrollOffset + i;
340+ const isHighlighted = globalIndex === highlightIndex;
341+
342+ if (isHighlighted) {
343+ children.push(
344+ HStack(
345+ {
346+ onClick: () => onSelect(item.value),
347+ focusable: false,
348+ },
349+ [
350+ Text(`${indicator} `, { fgColor: highlightColor }),
351+ Text(item.label, { fgColor: highlightColor }),
352+ ],
353+ ),
354+ );
355+ } else {
356+ children.push(
357+ HStack(
358+ {
359+ onClick: () => onSelect(item.value),
360+ focusable: false,
361+ },
362+ [Text(" "), Text(item.label)],
363+ ),
364+ );
365+ }
366+ }
367+ }
368+
369+ // Overflow indicator
370+ if (overflow > 0) {
371+ children.push(
372+ HStack({}, [Text(` ${overflow} more`, { fgColor: "brightBlack" })]),
373+ );
374+ }
375+
376+ return VStack(
377+ {
378+ onKeyPress: handleKey,
379+ focusable: focusable ?? true,
380+ focused,
381+ onFocus,
382+ onBlur,
383+ focusStyle,
384+ width,
385+ height,
386+ flex,
387+ fgColor,
388+ bgColor,
389+ },
390+ children,
391+ );
392+ }
393+
394+ render.reset = () => {
395+ query = "";
396+ highlightIndex = 0;
397+ scrollOffset = 0;
398+ };
399+
400+ return render as SelectInstance;
401+}
packages/core/src/cel.ts+5−6
@@ -420,12 +420,11 @@ function findClickFocusTarget(path: LayoutNode[]): LayoutNode | null {
420420 for (let i = path.length - 1; i >= 0; i--) {
421421 const node = path[i]!.node;
422422 if (node.type === "textinput") return path[i]!;
423- if (
424- (node.type === "vstack" || node.type === "hstack") &&
425- node.props.onClick &&
426- node.props.focusable !== false
427- ) {
428- return path[i]!;
423+ if (node.type === "vstack" || node.type === "hstack") {
424+ const isFocusable =
425+ node.props.focusable === true ||
426+ (node.props.onClick != null && node.props.focusable !== false);
427+ if (isFocusable) return path[i]!;
429428 }
430429 }
431430 return null;
packages/core/src/hit-test.test.ts+10−0
@@ -186,4 +186,14 @@ describe("collectFocusable", () => {
186186 const focusable = collectFocusable(ln);
187187 expect(focusable.length).toBe(3);
188188 });
189+
190+ test("explicit focusable: true without onClick is focusable", () => {
191+ const node = VStack({ width: 20, height: 10 }, [
192+ HStack({ focusable: true }, [Text("keyboard-only")]),
193+ HStack({ onClick: () => {} }, [Text("clickable")]),
194+ ]);
195+ const ln = layout(node, 20, 10);
196+ const focusable = collectFocusable(ln);
197+ expect(focusable.length).toBe(2);
198+ });
189199 });
packages/core/src/hit-test.ts+6−2
@@ -118,7 +118,8 @@ export function findKeyPressHandler(
118118 *
119119 * A node is focusable if:
120120 * - It's a TextInput (always focusable), OR
121- * - It's a container with `onClick` and `focusable` is not `false`
121+ * - It's a container with `onClick` and `focusable` is not `false`, OR
122+ * - It's a container with explicit `focusable: true`
122123 *
123124 * @param root - Root of the layout tree.
124125 * @returns Focusable nodes in document order.
@@ -135,7 +136,10 @@ function collectFocusableRecursive(ln: LayoutNode, result: LayoutNode[]): void {
135136 if (node.type === "textinput") {
136137 result.push(ln);
137138 } else if (node.type === "vstack" || node.type === "hstack") {
138- if (node.props.onClick && node.props.focusable !== false) {
139+ const isFocusable =
140+ node.props.focusable === true ||
141+ (node.props.onClick != null && node.props.focusable !== false);
142+ if (isFocusable) {
139143 result.push(ln);
140144 }
141145 }