diff --git a/src/List.tsx b/src/List.tsx index 6035557e..e07fa654 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -45,6 +45,8 @@ export interface ListProps extends React.HTMLAttributes { data: T[]; height?: number; itemHeight?: number; + /** If not match virtual scroll condition, Set List still use height of container. */ + fullHeight?: boolean; itemKey: string | ((item: T) => string); component?: string | React.FC | React.ComponentClass; disabled?: boolean; @@ -706,6 +708,7 @@ class List extends React.Component, ListState> { component: Component = 'div', height, itemHeight, + fullHeight = true, data, children, itemKey, @@ -726,7 +729,11 @@ class List extends React.Component, ListState> { return ( { expect(wrapper.find(Filler).props().offset).toBeFalsy(); }); - it('height over itemHeight', () => { - const wrapper = genList({ data: genData(1), itemHeight: 1, height: 999 }); + describe('height over itemHeight', () => { + it('full height', () => { + const wrapper = genList({ data: genData(1), itemHeight: 1, height: 999 }); + expect(wrapper.find(Filler).props().offset).toBeFalsy(); + expect(wrapper.find('ul').props().style).toEqual(expect.objectContaining({ height: 999 })); + }); - expect(wrapper.find(Filler).props().offset).toBeFalsy(); + it('without full height', () => { + const wrapper = genList({ + data: genData(1), + itemHeight: 1, + height: 999, + fullHeight: false, + }); + expect(wrapper.find(Filler).props().offset).toBeFalsy(); + expect(wrapper.find('ul').props().style).toEqual( + expect.objectContaining({ maxHeight: 999 }), + ); + }); }); });