feat(onFocus): pan nodes into the viewport on tab

This commit is contained in:
Abbey Yacoe
2025-06-02 16:00:42 +02:00
parent 3b36b7c8a6
commit a488322c55
2 changed files with 36 additions and 0 deletions
@@ -196,6 +196,27 @@
store.moveSelectedNodes(arrowKeyDiffs[event.key], event.shiftKey ? 4 : 1);
}
}
function onFocus() {
if (store.disableKeyboardA11y) {
return;
}
const zoom = store.panZoom?.getViewport().zoom ?? 1;
// Get node dimensions
const nodeWidth = nodeRef?.offsetWidth || 0;
const nodeHeight = nodeRef?.offsetHeight || 0;
store.panZoom?.setViewport(
{
x: -(positionX + nodeWidth / 2) * zoom + window.innerWidth / 2,
y: -(positionY + nodeHeight / 2) * zoom + window.innerHeight / 2,
zoom: zoom,
},
{ duration: 100 }
);
}
</script>
{#if !hidden}
@@ -251,6 +272,7 @@
? (event) => onnodecontextmenu({ node: userNode, event })
: undefined}
onkeydown={focusable ? onKeyDown : undefined}
onfocus={focusable ? onFocus : undefined}
tabIndex={focusable ? 0 : undefined}
role={focusable ? 'button' : undefined}
aria-describedby={store.disableKeyboardA11y