Skip to content

chore: not add attr #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
containerProps.dir = 'rtl';
}

if (process.env.NODE_ENV !== 'production') {
containerProps['data-dev-offset-top'] = offsetTop;
}

return (
<div
ref={containerRef}
Expand Down
30 changes: 24 additions & 6 deletions tests/scroll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ function genData(count) {
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
}

// Mock ScrollBar
jest.mock('../src/ScrollBar', () => {
const OriScrollBar = jest.requireActual('../src/ScrollBar').default;
const React = jest.requireActual('react');
return React.forwardRef((props, ref) => {
const { scrollOffset } = props;

return (
<div data-dev-offset={scrollOffset}>
<OriScrollBar {...props} ref={ref} />
</div>
);
});
});

describe('List.Scroll', () => {
let mockElement;
let boundingRect = {
Expand Down Expand Up @@ -525,13 +540,16 @@ describe('List.Scroll', () => {
await Promise.resolve();
});

expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute(
'data-dev-offset-top',
'0',
);
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute(
'data-dev-offset-top',
// inner
expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute(
'data-dev-offset',
'10',
);

// outer
expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute(
'data-dev-offset',
'0',
);
});
});
30 changes: 22 additions & 8 deletions tests/touch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ import React from 'react';
import List from '../src';
import { spyElementPrototypes } from './utils/domHook';

// Mock ScrollBar
jest.mock('../src/ScrollBar', () => {
const OriScrollBar = jest.requireActual('../src/ScrollBar').default;
const React = jest.requireActual('react');
return React.forwardRef((props, ref) => {
const { scrollOffset } = props;

return (
<div data-dev-offset={scrollOffset}>
<OriScrollBar {...props} ref={ref} />
</div>
);
});
});

function genData(count) {
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
}
Expand Down Expand Up @@ -161,17 +176,16 @@ describe('List.Touch', () => {
await Promise.resolve();
});

expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute(
'data-dev-offset-top',
// inner not to be 0
expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute('data-dev-offset');
expect(container.querySelectorAll('[data-dev-offset]')[0]).not.toHaveAttribute(
'data-dev-offset',
'0',
);

// inner not to be 0
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute(
'data-dev-offset-top',
);
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).not.toHaveAttribute(
'data-dev-offset-top',
// outer
expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute(
'data-dev-offset',
'0',
);
});
Expand Down
Loading