react-window 1.8.7 → 1.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-window",
3
- "version": "1.8.7",
3
+ "version": "1.8.8",
4
4
  "description": "React components for efficiently rendering large, scrollable lists and tabular data",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com> (https://github.com/bvaughn/)",
6
6
  "contributors": [
@@ -4,6 +4,8 @@ import createListComponent from './createListComponent';
4
4
 
5
5
  import type { Props, ScrollToAlign } from './createListComponent';
6
6
 
7
+ type InstanceProps = any;
8
+
7
9
  const FixedSizeList = createListComponent({
8
10
  getItemOffset: ({ itemSize }: Props<any>, index: number): number =>
9
11
  index * ((itemSize: any): number),
@@ -18,7 +20,9 @@ const FixedSizeList = createListComponent({
18
20
  { direction, height, itemCount, itemSize, layout, width }: Props<any>,
19
21
  index: number,
20
22
  align: ScrollToAlign,
21
- scrollOffset: number
23
+ scrollOffset: number,
24
+ instanceProps: InstanceProps,
25
+ scrollbarSize: number
22
26
  ): number => {
23
27
  // TODO Deprecate direction "horizontal"
24
28
  const isHorizontal = direction === 'horizontal' || layout === 'horizontal';
@@ -33,7 +37,10 @@ const FixedSizeList = createListComponent({
33
37
  );
34
38
  const minOffset = Math.max(
35
39
  0,
36
- index * ((itemSize: any): number) - size + ((itemSize: any): number)
40
+ index * ((itemSize: any): number) -
41
+ size +
42
+ ((itemSize: any): number) +
43
+ scrollbarSize
37
44
  );
38
45
 
39
46
  if (align === 'smart') {
@@ -183,7 +183,8 @@ const VariableSizeList = createListComponent({
183
183
  index: number,
184
184
  align: ScrollToAlign,
185
185
  scrollOffset: number,
186
- instanceProps: InstanceProps
186
+ instanceProps: InstanceProps,
187
+ scrollbarSize: number
187
188
  ): number => {
188
189
  const { direction, height, layout, width } = props;
189
190
 
@@ -202,7 +203,7 @@ const VariableSizeList = createListComponent({
202
203
  );
203
204
  const minOffset = Math.max(
204
205
  0,
205
- itemMetadata.offset - size + itemMetadata.size
206
+ itemMetadata.offset - size + itemMetadata.size + scrollbarSize
206
207
  );
207
208
 
208
209
  if (align === 'smart') {
@@ -3,7 +3,7 @@
3
3
  import memoizeOne from 'memoize-one';
4
4
  import { createElement, PureComponent } from 'react';
5
5
  import { cancelTimeout, requestTimeout } from './timer';
6
- import { getRTLOffsetType } from './domHelpers';
6
+ import { getScrollbarSize, getRTLOffsetType } from './domHelpers';
7
7
 
8
8
  import type { TimeoutID } from './timer';
9
9
 
@@ -213,18 +213,38 @@ export default function createListComponent({
213
213
  }
214
214
 
215
215
  scrollToItem(index: number, align: ScrollToAlign = 'auto'): void {
216
- const { itemCount } = this.props;
216
+ const { itemCount, layout } = this.props;
217
217
  const { scrollOffset } = this.state;
218
218
 
219
219
  index = Math.max(0, Math.min(index, itemCount - 1));
220
220
 
221
+ // The scrollbar size should be considered when scrolling an item into view, to ensure it's fully visible.
222
+ // But we only need to account for its size when it's actually visible.
223
+ // This is an edge case for lists; normally they only scroll in the dominant direction.
224
+ let scrollbarSize = 0;
225
+ if (this._outerRef) {
226
+ const outerRef = ((this._outerRef: any): HTMLElement);
227
+ if (layout === 'vertical') {
228
+ scrollbarSize =
229
+ outerRef.scrollWidth > outerRef.clientWidth
230
+ ? getScrollbarSize()
231
+ : 0;
232
+ } else {
233
+ scrollbarSize =
234
+ outerRef.scrollHeight > outerRef.clientHeight
235
+ ? getScrollbarSize()
236
+ : 0;
237
+ }
238
+ }
239
+
221
240
  this.scrollTo(
222
241
  getOffsetForIndexAndAlignment(
223
242
  this.props,
224
243
  index,
225
244
  align,
226
245
  scrollOffset,
227
- this._instanceProps
246
+ this._instanceProps,
247
+ scrollbarSize
228
248
  )
229
249
  );
230
250
  }