Skip to content

Commit

Permalink
feat: add offsetX to renderFn (#269)
Browse files Browse the repository at this point in the history
* feat: add offsetX to renderFn

* test: add case
  • Loading branch information
linxianxi committed May 20, 2024
1 parent 37ed992 commit b438d2d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
start,
end,
scrollWidth,
offsetLeft,
setInstanceRef,
children,
sharedConfig,
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useChildren.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import type { SharedConfig, RenderFunc } from '../interface';
import type { RenderFunc, SharedConfig } from '../interface';
import { Item } from '../Item';

export default function useChildren<T>(
list: T[],
startIndex: number,
endIndex: number,
scrollWidth: number,
offsetX: number,
setNodeRef: (item: T, element: HTMLElement) => void,
renderFunc: RenderFunc<T>,
{ getKey }: SharedConfig<T>,
Expand All @@ -17,6 +18,7 @@ export default function useChildren<T>(
style: {
width: scrollWidth,
},
offsetX,
}) as React.ReactElement;

const key = getKey(item);
Expand Down
2 changes: 1 addition & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type RenderFunc<T> = (
item: T,
index: number,
props: { style?: React.CSSProperties },
props: { style: React.CSSProperties; offsetX: number },
) => React.ReactNode;

export interface SharedConfig<T> {
Expand Down
13 changes: 13 additions & 0 deletions tests/props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ describe('Props', () => {

expect(wrapper.find('.prefix-holder-inner').length).toBeTruthy();
});

it('offsetX in renderFn', () => {
let scrollLeft;
mount(
<List data={[0]} itemKey={id => id} prefixCls="prefix">
{(id, _, { offsetX }) => {
scrollLeft = offsetX;
return <div>{id}</div>}}
</List>,
);

expect(scrollLeft).toEqual(0);
});
});

0 comments on commit b438d2d

Please sign in to comment.