Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Forbedrer logging av piltast-navigasjon
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-nom committed Mar 5, 2024
1 parent be5802b commit ae85b7e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/keyboard-navigation/kb-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ export const selectNode = (node: KbNavNode, callback: NodeSetterCallback = () =>
if (!element) {
return;
}
logAmplitudeEvent('piltast-navigasjon', { linkId: node.id, linkGroup: node.group });
callback(node);
if (focus) {
element.focus();
scrollIfNearViewBounds(element);
}
};

const logArrowKeyUsage = (node: KbNavNode) =>
logAmplitudeEvent('piltast-navigasjon-2', { linkId: node.id, linkGroup: node.group });

const arrowkeysHandler = (currentNode: KbNavNode, setCurrentNode: NodeSetterCallback) => (event: KeyboardEvent) => {
if (!currentNode?.id) {
return;
Expand All @@ -138,18 +140,22 @@ const arrowkeysHandler = (currentNode: KbNavNode, setCurrentNode: NodeSetterCall
return;
}
selectNode(currentNode[NodeEdge.Left], setCurrentNode);
logArrowKeyUsage(currentNode);
break;
case 'ArrowUp':
selectNode(currentNode[NodeEdge.Top], setCurrentNode);
logArrowKeyUsage(currentNode);
break;
case 'ArrowRight':
if (isInputField(currentNode)) {
return;
}
selectNode(currentNode[NodeEdge.Right], setCurrentNode);
logArrowKeyUsage(currentNode);
break;
case 'ArrowDown':
selectNode(currentNode[NodeEdge.Bottom], setCurrentNode);
logArrowKeyUsage(currentNode);
break;
default:
return;
Expand Down

0 comments on commit ae85b7e

Please sign in to comment.