diff --git a/src/List.tsx b/src/List.tsx index ac4029d..8a850c8 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -504,6 +504,7 @@ export function RawList(props: ListProps, ref: React.Ref) { start, end, scrollWidth, + offsetLeft, setInstanceRef, children, sharedConfig, diff --git a/src/hooks/useChildren.tsx b/src/hooks/useChildren.tsx index 8b0bfe6..8c4fdf6 100644 --- a/src/hooks/useChildren.tsx +++ b/src/hooks/useChildren.tsx @@ -1,5 +1,5 @@ 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( @@ -7,6 +7,7 @@ export default function useChildren( startIndex: number, endIndex: number, scrollWidth: number, + offsetX: number, setNodeRef: (item: T, element: HTMLElement) => void, renderFunc: RenderFunc, { getKey }: SharedConfig, @@ -17,6 +18,7 @@ export default function useChildren( style: { width: scrollWidth, }, + offsetX, }) as React.ReactElement; const key = getKey(item); diff --git a/src/interface.ts b/src/interface.ts index f5431a3..e0fd765 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,7 +1,7 @@ export type RenderFunc = ( item: T, index: number, - props: { style?: React.CSSProperties }, + props: { style: React.CSSProperties; offsetX: number }, ) => React.ReactNode; export interface SharedConfig { diff --git a/tests/props.test.js b/tests/props.test.js index 45edeff..bbc41e8 100644 --- a/tests/props.test.js +++ b/tests/props.test.js @@ -40,4 +40,17 @@ describe('Props', () => { expect(wrapper.find('.prefix-holder-inner').length).toBeTruthy(); }); + + it('offsetX in renderFn', () => { + let scrollLeft; + mount( + id} prefixCls="prefix"> + {(id, _, { offsetX }) => { + scrollLeft = offsetX; + return
{id}
}} +
, + ); + + expect(scrollLeft).toEqual(0); + }); });