From 64cfc56ccd4d5b09383c87c54c767a7736fcd5e8 Mon Sep 17 00:00:00 2001 From: seb Date: Sun, 11 Oct 2026 19:46:22 +0200 Subject: [PATCH] u --- src/FillSpace.jsx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/FillSpace.jsx b/src/FillSpace.jsx index 7c602ad..85d9dec 100644 --- a/src/FillSpace.jsx +++ b/src/FillSpace.jsx @@ -122,16 +122,19 @@ class FillSpace extends Component { Array.isArray(this.props.items) && this.props.items !== prevProps.items ) { + const explicitTotal = this.props.unfilteredCount ?? this.props.totalCount; + const total = + explicitTotal != null ? Number(explicitTotal) : this.props.items.length; const pageCount = Math.max( 1, - Math.ceil(this.props.items.length / Math.max(1, this.state.pageSize)), + Math.ceil(total / Math.max(1, this.state.pageSize)), ); if (this.state.currentPage > pageCount) { this.setState({ currentPage: pageCount }); this.props.onPageChange?.(pageCount, { pageCount, pageSize: this.state.pageSize, - total: this.props.items.length, + total, }); } } @@ -245,11 +248,13 @@ class FillSpace extends Component { } _handleWheel = (event) => { - const { items } = this.props; + const { items, totalCount, unfilteredCount } = this.props; if (!Array.isArray(items)) return; if (this.ref && event.target && !this.ref.contains(event.target)) return; const { pageSize, currentPage } = this.state; - const pageCount = Math.max(1, Math.ceil(items.length / Math.max(1, pageSize))); + const explicitTotal = unfilteredCount ?? totalCount; + const total = explicitTotal != null ? Number(explicitTotal) : items.length; + const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize))); const delta = event.deltaY || 0; if (pageCount <= 1) return; if (delta === 0) return; @@ -267,8 +272,14 @@ class FillSpace extends Component { }; _goToPage = (page) => { - const { items, onPageChange } = this.props; - const total = Array.isArray(items) ? items.length : 0; + const { items, onPageChange, totalCount, unfilteredCount } = this.props; + const explicitTotal = unfilteredCount ?? totalCount; + const total = + explicitTotal != null + ? Number(explicitTotal) + : Array.isArray(items) + ? items.length + : 0; const pageCount = Math.max(1, Math.ceil(total / Math.max(1, this.state.pageSize))); const next = Math.min(Math.max(1, Number(page) || 1), pageCount); if (next === this.state.currentPage) return; @@ -305,8 +316,9 @@ class FillSpace extends Component { // type or callback). `items` may be undefined while data is loading. const { pageSize, currentPage, viewportHeight } = this.state; const list = Array.isArray(items) ? items : []; - const total = list.length; - const fullTotal = unfilteredCount ?? totalCount ?? Math.max(this.maxSeenCount || 0, total); + const explicitTotal = unfilteredCount ?? totalCount; + const total = explicitTotal != null ? Number(explicitTotal) : list.length; + const fullTotal = Math.max(this.maxSeenCount || 0, total); const needsPaginationContainer = fullTotal > pageSize; const showPaginationControls = total > pageSize; const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));