Skip to content

Commit

Permalink
feat: tree component API for virtual tree
Browse files Browse the repository at this point in the history
- refactored Tree key handler based on the pr comments
  • Loading branch information
maxinteger committed Aug 27, 2024
1 parent f377b57 commit e84826d
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/components/Tree/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,25 @@ const Tree: FC<Props> = (props: Props) => {
const { keyboardProps } = useKeyboard({
onKeyDown: (evt) => {
const key = evt.key as TreeNavKeyCodes;
if (TREE_NAVIGATION_KEYS.includes(key)) {
evt.preventDefault();
const nextActiveNode = getNextActiveNode(
tree,
activeNodeId,
key,
excludeTreeRoot,
toggleTreeNode
);
setActiveNodeId(nextActiveNode);
} else {
evt.continuePropagation();
switch (key) {
case 'ArrowUp':
case 'ArrowDown':
case 'ArrowRight':
case 'ArrowLeft': {
evt.preventDefault();
const nextActiveNode = getNextActiveNode(
tree,
activeNodeId,
key,
excludeTreeRoot,
toggleTreeNode
);
setActiveNodeId(nextActiveNode);
break;
}
default:
evt.continuePropagation();
break;
}
},
});
Expand Down

0 comments on commit e84826d

Please sign in to comment.