Skip to content

Commit 52f20db

Browse files
authored
chore: not add attr (#289)
1 parent bea7eb4 commit 52f20db

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

src/List.tsx

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

564-
if (process.env.NODE_ENV !== 'production') {
565-
containerProps['data-dev-offset-top'] = offsetTop;
566-
}
567-
568564
return (
569565
<div
570566
ref={containerRef}

tests/scroll.test.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ function genData(count) {
1111
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
1212
}
1313

14+
// Mock ScrollBar
15+
jest.mock('../src/ScrollBar', () => {
16+
const OriScrollBar = jest.requireActual('../src/ScrollBar').default;
17+
const React = jest.requireActual('react');
18+
return React.forwardRef((props, ref) => {
19+
const { scrollOffset } = props;
20+
21+
return (
22+
<div data-dev-offset={scrollOffset}>
23+
<OriScrollBar {...props} ref={ref} />
24+
</div>
25+
);
26+
});
27+
});
28+
1429
describe('List.Scroll', () => {
1530
let mockElement;
1631
let boundingRect = {
@@ -525,13 +540,16 @@ describe('List.Scroll', () => {
525540
await Promise.resolve();
526541
});
527542

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',
543+
// inner
544+
expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute(
545+
'data-dev-offset',
534546
'10',
535547
);
548+
549+
// outer
550+
expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute(
551+
'data-dev-offset',
552+
'0',
553+
);
536554
});
537555
});

tests/touch.test.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ import React from 'react';
44
import List from '../src';
55
import { spyElementPrototypes } from './utils/domHook';
66

7+
// Mock ScrollBar
8+
jest.mock('../src/ScrollBar', () => {
9+
const OriScrollBar = jest.requireActual('../src/ScrollBar').default;
10+
const React = jest.requireActual('react');
11+
return React.forwardRef((props, ref) => {
12+
const { scrollOffset } = props;
13+
14+
return (
15+
<div data-dev-offset={scrollOffset}>
16+
<OriScrollBar {...props} ref={ref} />
17+
</div>
18+
);
19+
});
20+
});
21+
722
function genData(count) {
823
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
924
}
@@ -161,17 +176,16 @@ describe('List.Touch', () => {
161176
await Promise.resolve();
162177
});
163178

164-
expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute(
165-
'data-dev-offset-top',
179+
// inner not to be 0
180+
expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute('data-dev-offset');
181+
expect(container.querySelectorAll('[data-dev-offset]')[0]).not.toHaveAttribute(
182+
'data-dev-offset',
166183
'0',
167184
);
168185

169-
// inner not to be 0
170-
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute(
171-
'data-dev-offset-top',
172-
);
173-
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).not.toHaveAttribute(
174-
'data-dev-offset-top',
186+
// outer
187+
expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute(
188+
'data-dev-offset',
175189
'0',
176190
);
177191
});

0 commit comments

Comments
 (0)