From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- shared/components/src/actions/focus-node.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 shared/components/src/actions/focus-node.ts (limited to 'shared/components/src/actions/focus-node.ts') diff --git a/shared/components/src/actions/focus-node.ts b/shared/components/src/actions/focus-node.ts new file mode 100644 index 0000000..907f584 --- /dev/null +++ b/shared/components/src/actions/focus-node.ts @@ -0,0 +1,19 @@ +export default function focusNode( + node: HTMLElement, + focusedIndex: number | null, +) { + const nodeIndex = Number(node.getAttribute('data-index')); + + // Handle the initial focus when applicable + if (nodeIndex === focusedIndex) { + node.focus(); + } + + return { + update(newFocusedIndex) { + if (nodeIndex === newFocusedIndex) { + node.focus(); + } + }, + }; +} -- cgit v1.2.3