diff --git a/package.json b/package.json index 4c34d2c..6409768 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@decathlon/react-table", - "version": "1.15.2", + "version": "1.15.3", "description": "React components for efficiently rendering large tabular data", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/components/scroller.tsx b/src/components/scroller.tsx index c825161..368cc60 100644 --- a/src/components/scroller.tsx +++ b/src/components/scroller.tsx @@ -126,9 +126,9 @@ class Scroller extends React.Component { const verticalScrollBar = hasVerticalScrollBar ? SCROLLBAR_SIZE : 0; const horizontalScrollBar = hasHorizontalScrollBar ? SCROLLBAR_SIZE : 0; // We calculate the maximum value of the scroll - this.scrollTopMax = virtualHeight - height + horizontalScrollBar; + this.scrollTopMax = virtualHeight - height - 5 + horizontalScrollBar; // We calculate the maximum value of the scroll left - this.scrollLeftMax = virtualWidth - width + verticalScrollBar; + this.scrollLeftMax = virtualWidth - width - 5 + verticalScrollBar; }; public getScrollDirections = (): ScrollDirection[] => { diff --git a/src/components/virtualizer.tsx b/src/components/virtualizer.tsx index 9d18250..44bd5ab 100644 --- a/src/components/virtualizer.tsx +++ b/src/components/virtualizer.tsx @@ -354,13 +354,13 @@ class Virtualizer extends React.Component { const newRowsState = hasVerticallyScrolled ? this.getVisibleRowsState(scrollTop) : null; const newColumnsState = hasHorizontalyScrolled ? this.getVisibleColumnsState(scrollLeft) : null; - if (newRowsState || newColumnsState) { - // @ts-ignore - this.setState({ ...newRowsState, ...newColumnsState }, () => { + const handleOnScroll = (): void => { + if (onScroll || onHorizontallyScroll || onVerticallyScroll) { const { visibleColumnIndexes, visibleRowIndexes } = this.state; const columnsCursor = findFirstNotIncluded(visibleColumnIndexes, this.visibleFixedColumns); const rowsCursor = findFirstNotIncluded(visibleRowIndexes, this.visibleFixedRows); - onScroll && + + if (onScroll) { onScroll({ scrollValues, newColumnsState, @@ -368,14 +368,25 @@ class Virtualizer extends React.Component { columnsCursor, rowsCursor }); - onHorizontallyScroll && + } + if (onHorizontallyScroll) { onHorizontallyScroll({ scrollValues, newColumnsState, columnsCursor }); - onVerticallyScroll && onVerticallyScroll({ scrollValues, newRowsState, rowsCursor }); - }); + } + if (onVerticallyScroll) { + onVerticallyScroll({ scrollValues, newRowsState, rowsCursor }); + } + } + }; + + if (newRowsState || newColumnsState) { + // @ts-ignore + this.setState({ ...newRowsState, ...newColumnsState }, handleOnScroll); + } else { + handleOnScroll(); } }; diff --git a/test/components/scroller.test.tsx b/test/components/scroller.test.tsx index 6099f80..08e86f4 100644 --- a/test/components/scroller.test.tsx +++ b/test/components/scroller.test.tsx @@ -85,7 +85,7 @@ describe("Scroller component", () => { const onScroll = jest.fn(); const wrapper = mount(); const scrollerInstance: Scroller = wrapper.instance() as Scroller; - const maxScrollTop = scrollerProps.virtualHeight - scrollerProps.height + SCROLLBAR_SIZE; + const maxScrollTop = scrollerProps.virtualHeight - scrollerProps.height - 5 + SCROLLBAR_SIZE; scrollerInstance.scrollToTop(maxScrollTop); // @ts-ignore scrollOrigin is private expect(scrollerInstance.scrollOrigin).toBe("external"); @@ -156,7 +156,7 @@ describe("Scroller component", () => { const onScroll = jest.fn(); const wrapper = mount(); const scrollerInstance: Scroller = wrapper.instance() as Scroller; - const maxScrollLeft = scrollerProps.virtualWidth - scrollerProps.width + SCROLLBAR_SIZE; + const maxScrollLeft = scrollerProps.virtualWidth - scrollerProps.width - 5 + SCROLLBAR_SIZE; scrollerInstance.scrollToLeft(maxScrollLeft); // @ts-ignore scrollOrigin is private expect(scrollerInstance.scrollOrigin).toBe("external");