Skip to content

Commit cb3ca3b

Browse files
committed
Bug fixes
1 parent bf92ffd commit cb3ca3b

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 3.3.9
4+
> Date: 2021-12-07
5+
### Fixed
6+
- Selection was overflowing when pasting a single row that overflows to the right
7+
- A state could be updated (triggering a warning) after the component was unmounted
8+
39
## 3.3.8
410
> Date: 2021-12-05
511
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-datasheet-grid",
3-
"version": "3.3.8",
3+
"version": "3.3.9",
44
"description": "An Excel-like React component to create beautiful spreadsheets.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/components/DataSheetGrid.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,10 @@ export const DataSheetGrid = React.memo(
669669
onChange(newData)
670670
setActiveCell({ col: min.col, row: min.row })
671671
setSelectionCell({
672-
col: min.col + pasteData[0].length - 1,
672+
col: Math.min(
673+
min.col + pasteData[0].length - 1,
674+
columns.length - (hasStickyRightColumn ? 3 : 2)
675+
),
673676
row: max.row,
674677
})
675678
} else {

src/hooks/useDebounceState.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { useMemo, useState } from 'react'
1+
import { useEffect, useMemo, useRef, useState } from 'react'
22
import { debounce } from 'throttle-debounce'
33

44
export const useDebounceState = <T>(
55
defaultValue: T,
66
delay: number
77
): [T, (nextVal: T) => void] => {
88
const [debouncedValue, setDebouncedValue] = useState(defaultValue)
9+
const cancelRef = useRef<debounce<(newValue: T) => void>>()
10+
11+
useEffect(() => () => cancelRef.current?.cancel(), [])
912

1013
const setValue = useMemo(
1114
() =>
12-
debounce(delay, (newValue: T) => {
15+
(cancelRef.current = debounce(delay, (newValue: T) => {
1316
setDebouncedValue(newValue)
14-
}),
17+
})),
1518
[delay]
1619
)
1720

tests/paste.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import React from 'react'
22
import '@testing-library/jest-dom'
3-
import userEvent from '@testing-library/user-event'
4-
import { render, screen, act, fireEvent, waitFor } from '@testing-library/react'
3+
import { act, fireEvent, render, waitFor } from '@testing-library/react'
54
import {
6-
DataSheetGrid,
75
Column,
8-
textColumn,
9-
keyColumn,
6+
DataSheetGrid,
107
DataSheetGridRef,
8+
keyColumn,
9+
textColumn,
1110
} from '../src'
1211

1312
jest.mock('react-resize-detector', () => ({

0 commit comments

Comments
 (0)