Skip to content

Commit 604a640

Browse files
committed
[Data Grid] Account for text being selected when cell scrolls into view
1 parent 430a5e9 commit 604a640

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

packages/eui/src/components/datagrid/utils/scrolling.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ export const useScroll = (args: Dependencies) => {
5252
const { focusedCell } = useContext(DataGridFocusContext);
5353
useEffect(() => {
5454
if (focusedCell) {
55-
scrollCellIntoView({
56-
rowIndex: focusedCell[1],
57-
colIndex: focusedCell[0],
58-
});
55+
setTimeout(() => {
56+
// do not scroll if text is being selected
57+
// (120ms feels almost instant when clicking
58+
// but seems enough time to catch the text selection)
59+
if (window?.getSelection()?.type === 'Range') {
60+
return;
61+
}
62+
scrollCellIntoView({
63+
rowIndex: focusedCell[1],
64+
colIndex: focusedCell[0],
65+
});
66+
}, 120);
5967
}
6068
}, [focusedCell, scrollCellIntoView]);
6169

0 commit comments

Comments
 (0)