Skip to content

Commit cc982cb

Browse files
authored
Prevent scrolling to nodes on scroll (#77)
* Check that a focused node is not already focused before running .focus() on the underlying DOM element * use preventScroll to avoid scrolling on mount
1 parent 1372a52 commit cc982cb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

packages/react-arborist/src/components/row-container.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useMemo, useRef } from "react";
22
import { useDataUpdates, useNodesContext, useTreeApi } from "../context";
33
import { useDragHook } from "../dnd/drag-hook";
44
import { useDropHook } from "../dnd/drop-hook";
5-
import { IdObj } from "../types/utils";
65
import { useFreshNode } from "../hooks/use-fresh-node";
76

87
type Props = {
@@ -68,7 +67,7 @@ export const RowContainer = React.memo(function RowContainer<T>({
6867

6968
useEffect(() => {
7069
if (!node.isEditing && node.isFocused) {
71-
el.current?.focus();
70+
el.current?.focus({ preventScroll: true });
7271
}
7372
}, [node.isEditing, node.isFocused, el.current]);
7473

0 commit comments

Comments
 (0)