forked from off-topic/apps.apple.com
init commit
This commit is contained in:
19
shared/components/src/actions/focus-node.ts
Normal file
19
shared/components/src/actions/focus-node.ts
Normal file
@@ -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();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user