Skip to content
Permalink
Browse files
fix: Tree scrolling elements into view
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 eef48dcc547dae6146a3b2fd04c7a2ad13043036
Showing 1 changed file with 10 additions and 1 deletion.
@@ -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":
@@ -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": {

0 comments on commit eef48dc

Please sign in to comment.