Skip to content

Commit 20f9769

Browse files
authored
feat: Add innerProps (#194)
1 parent 09b3ae9 commit 20f9769

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Filler.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as React from 'react';
22
import ResizeObserver from 'rc-resize-observer';
33
import classNames from 'classnames';
44

5+
export type InnerProps = Pick<React.HTMLAttributes<HTMLDivElement>, 'role' | 'id'>;
6+
57
interface FillerProps {
68
prefixCls?: string;
79
/** Virtual filler height. Should be `count * itemMinHeight` */
@@ -12,14 +14,16 @@ interface FillerProps {
1214
children: React.ReactNode;
1315

1416
onInnerResize?: () => void;
17+
18+
innerProps?: InnerProps;
1519
}
1620

1721
/**
1822
* Fill component to provided the scroll content real height.
1923
*/
2024
const Filler = React.forwardRef(
2125
(
22-
{ height, offset, children, prefixCls, onInnerResize }: FillerProps,
26+
{ height, offset, children, prefixCls, onInnerResize, innerProps }: FillerProps,
2327
ref: React.Ref<HTMLDivElement>,
2428
) => {
2529
let outerStyle: React.CSSProperties = {};
@@ -57,6 +61,7 @@ const Filler = React.forwardRef(
5761
[`${prefixCls}-holder-inner`]: prefixCls,
5862
})}
5963
ref={ref}
64+
{...innerProps}
6065
>
6166
{children}
6267
</div>

src/List.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import { useRef, useState } from 'react';
33
import classNames from 'classnames';
44
import Filler from './Filler';
5+
import type { InnerProps } from './Filler';
56
import ScrollBar from './ScrollBar';
67
import type { RenderFunc, SharedConfig, GetKey } from './interface';
78
import useChildren from './hooks/useChildren';
@@ -53,6 +54,9 @@ export interface ListProps<T> extends Omit<React.HTMLAttributes<any>, 'children'
5354
onScroll?: React.UIEventHandler<HTMLElement>;
5455
/** Trigger when render list item changed */
5556
onVisibleChange?: (visibleList: T[], fullList: T[]) => void;
57+
58+
/** Inject to inner container props. Only use when you need pass aria related data */
59+
innerProps?: InnerProps;
5660
}
5761

5862
export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
@@ -70,6 +74,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
7074
component: Component = 'div',
7175
onScroll,
7276
onVisibleChange,
77+
innerProps,
7378
...restProps
7479
} = props;
7580

@@ -354,6 +359,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
354359
offset={offset}
355360
onInnerResize={collectHeight}
356361
ref={fillerInnerRef}
362+
innerProps={innerProps}
357363
>
358364
{listChildren}
359365
</Filler>

tests/list.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,19 @@ describe('List.Basic', () => {
211211
expect(collected).toBeTruthy();
212212
});
213213
});
214+
215+
it('innerProps', () => {
216+
const wrapper = genList({
217+
itemHeight: 20,
218+
height: 100,
219+
data: genData(100),
220+
virtual: false,
221+
innerProps: {
222+
role: 'listbox',
223+
id: `my_list`,
224+
},
225+
});
226+
227+
expect(wrapper.find('div#my_list').prop('role')).toEqual('listbox');
228+
});
214229
});

0 commit comments

Comments
 (0)