Skip to content

Commit ed864b0

Browse files
committed
feat: support fullHeight prop
1 parent 0579ebf commit ed864b0

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/List.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface ListProps<T> extends React.HTMLAttributes<any> {
4545
data: T[];
4646
height?: number;
4747
itemHeight?: number;
48+
/** If not match virtual scroll condition, Set List still use height of container. */
49+
fullHeight?: boolean;
4850
itemKey: string | ((item: T) => string);
4951
component?: string | React.FC<any> | React.ComponentClass<any>;
5052
disabled?: boolean;
@@ -706,6 +708,7 @@ class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
706708
component: Component = 'div',
707709
height,
708710
itemHeight,
711+
fullHeight = true,
709712
data,
710713
children,
711714
itemKey,
@@ -726,7 +729,11 @@ class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
726729

727730
return (
728731
<Component
729-
style={height ? { ...style, height, ...ScrollStyle } : style}
732+
style={
733+
height
734+
? { ...style, [fullHeight ? 'height' : 'maxHeight']: height, ...ScrollStyle }
735+
: style
736+
}
730737
className={mergedClassName}
731738
{...restProps}
732739
onScroll={this.onRawScroll}

tests/list.test.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,25 @@ describe('List', () => {
2929
expect(wrapper.find(Filler).props().offset).toBeFalsy();
3030
});
3131

32-
it('height over itemHeight', () => {
33-
const wrapper = genList({ data: genData(1), itemHeight: 1, height: 999 });
32+
describe('height over itemHeight', () => {
33+
it('full height', () => {
34+
const wrapper = genList({ data: genData(1), itemHeight: 1, height: 999 });
35+
expect(wrapper.find(Filler).props().offset).toBeFalsy();
36+
expect(wrapper.find('ul').props().style).toEqual(expect.objectContaining({ height: 999 }));
37+
});
3438

35-
expect(wrapper.find(Filler).props().offset).toBeFalsy();
39+
it('without full height', () => {
40+
const wrapper = genList({
41+
data: genData(1),
42+
itemHeight: 1,
43+
height: 999,
44+
fullHeight: false,
45+
});
46+
expect(wrapper.find(Filler).props().offset).toBeFalsy();
47+
expect(wrapper.find('ul').props().style).toEqual(
48+
expect.objectContaining({ maxHeight: 999 }),
49+
);
50+
});
3651
});
3752
});
3853

0 commit comments

Comments
 (0)