Skip to content

Commit 28f05e2

Browse files
authored
fix: scrollbar invisible (#237)
1 parent e9a9ecc commit 28f05e2

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/List.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
265265
const [size, setSize] = React.useState({ width: 0, height });
266266

267267
const onHolderResize: ResizeObserverProps['onResize'] = (sizeInfo) => {
268-
setSize(sizeInfo);
268+
setSize({
269+
width: sizeInfo.width || sizeInfo.offsetWidth,
270+
height: sizeInfo.height || sizeInfo.offsetHeight,
271+
});
269272
};
270273

271274
// Hack on scrollbar to enable flash call

tests/scroll.test.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import { spyElementPrototypes } from './utils/domHook';
55
import List from '../src';
66
import { createEvent, fireEvent, render } from '@testing-library/react';
77
import { resetWarned } from 'rc-util/lib/warning';
8+
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
9+
import '@testing-library/jest-dom';
810

911
function genData(count) {
1012
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
1113
}
1214

1315
describe('List.Scroll', () => {
1416
let mockElement;
17+
let boundingRect = {
18+
width: 100,
19+
height: 100,
20+
};
1521

1622
beforeAll(() => {
1723
mockElement = spyElementPrototypes(HTMLElement, {
@@ -21,10 +27,7 @@ describe('List.Scroll', () => {
2127
clientHeight: {
2228
get: () => 100,
2329
},
24-
getBoundingClientRect: () => ({
25-
width: 100,
26-
height: 100,
27-
}),
30+
getBoundingClientRect: () => boundingRect,
2831
offsetParent: {
2932
get: () => document.body,
3033
},
@@ -36,6 +39,10 @@ describe('List.Scroll', () => {
3639
});
3740

3841
beforeEach(() => {
42+
boundingRect = {
43+
width: 100,
44+
height: 100,
45+
};
3946
jest.useFakeTimers();
4047
});
4148

@@ -436,4 +443,34 @@ describe('List.Scroll', () => {
436443
).style.background,
437444
).toEqual('blue');
438445
});
446+
447+
it('scrollbar size should correct', async () => {
448+
boundingRect = {
449+
width: 0,
450+
height: 0,
451+
};
452+
453+
const { container } = genList(
454+
{
455+
itemHeight: 20,
456+
height: 100,
457+
data: genData(100),
458+
},
459+
render,
460+
);
461+
462+
await act(async () => {
463+
onLibResize([
464+
{
465+
target: container.querySelector('.rc-virtual-list-holder'),
466+
},
467+
]);
468+
469+
await Promise.resolve();
470+
});
471+
472+
expect(container.querySelector('.rc-virtual-list-scrollbar-thumb')).toHaveStyle({
473+
height: `10px`,
474+
});
475+
});
439476
});

0 commit comments

Comments
 (0)