Skip to content

Commit a00367c

Browse files
committed
chore: update
1 parent 5fc2c91 commit a00367c

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/List.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
563563
containerProps.dir = 'rtl';
564564
}
565565

566+
if (process.env.NODE_ENV !== 'production') {
567+
containerProps['data-dev-offset-top'] = offsetTop;
568+
}
569+
566570
return (
567571
<div
568572
ref={containerRef}

tests/scroll.test.js

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import '@testing-library/jest-dom';
2-
import { createEvent, fireEvent, render } from '@testing-library/react';
2+
import { act, createEvent, fireEvent, render } from '@testing-library/react';
33
import { mount } from 'enzyme';
44
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
55
import { resetWarned } from 'rc-util/lib/warning';
66
import React from 'react';
7-
import { act } from 'react-dom/test-utils';
87
import List from '../src';
98
import { spyElementPrototypes } from './utils/domHook';
109

@@ -51,11 +50,13 @@ describe('List.Scroll', () => {
5150
});
5251

5352
function genList(props, func = mount) {
54-
let node = (
55-
<List component="ul" itemKey="id" {...props}>
56-
{({ id }) => <li>{id}</li>}
57-
</List>
58-
);
53+
const mergedProps = {
54+
component: 'ul',
55+
itemKey: 'id',
56+
children: ({ id }) => <li>{id}</li>,
57+
...props,
58+
};
59+
let node = <List {...mergedProps} />;
5960

6061
if (props.ref) {
6162
node = <div>{node}</div>;
@@ -494,4 +495,43 @@ describe('List.Scroll', () => {
494495

495496
expect(container.querySelector('.rc-virtual-list-scrollbar-thumb')).toBeVisible();
496497
});
498+
499+
it('nest scroll', async () => {
500+
const { container } = genList(
501+
{
502+
itemHeight: 20,
503+
height: 100,
504+
data: genData(100),
505+
children: ({ id }) =>
506+
id === '0' ? (
507+
<li>
508+
<List component="ul" itemKey="id" itemHeight={20} height={100} data={genData(100)}>
509+
{({ id }) => <li>{id}</li>}
510+
</List>
511+
</li>
512+
) : (
513+
<li />
514+
),
515+
},
516+
render,
517+
);
518+
519+
fireEvent.wheel(container.querySelector('ul ul li'), {
520+
deltaY: 10,
521+
});
522+
523+
await act(async () => {
524+
jest.advanceTimersByTime(1000000);
525+
await Promise.resolve();
526+
});
527+
528+
expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute(
529+
'data-dev-offset-top',
530+
'0',
531+
);
532+
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute(
533+
'data-dev-offset-top',
534+
'10',
535+
);
536+
});
497537
});

0 commit comments

Comments
 (0)