Skip to content

Commit

Permalink
fix: Tree scrolling elements into view
Browse files Browse the repository at this point in the history
The tree will now correctly scroll the active item into view when using
the left and right arrow keys to jump to the expandable parent with the
left arrow key or to the first child with the right arrow key.
  • Loading branch information
mlaursen committed Jul 12, 2020
1 parent a9a0902 commit eef48dc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/tree/src/useTreeMovement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ export default function useTreeMovement({
if (!expandedIds.includes(itemId)) {
onItemExpansion(itemId, true);
} else {
setFocusedIndex(focusedIndex + 1);
const nextIndex = focusedIndex + 1;
const nextItem =
itemIdRefs[visibleItems[nextIndex]?.itemId]?.ref.current;

setFocusedIndex(nextIndex);
scrollIntoView(event.currentTarget, nextItem);
}
break;
case "ArrowLeft":
Expand All @@ -248,7 +253,11 @@ export default function useTreeMovement({
const parentIndex = visibleItems.findIndex(
(item) => item.itemId === parentId
);
const parentItem =
itemIdRefs[visibleItems[parentIndex]?.itemId]?.ref.current;

setFocusedIndex(parentIndex);
scrollIntoView(event.currentTarget, parentItem);
}
break;
case "a": {
Expand Down

0 comments on commit eef48dc

Please sign in to comment.