diff --git a/src/contentLayout/__tests__/contentLayout.test.tsx b/src/contentLayout/__tests__/contentLayout.test.tsx index 7032d49b0..5ed3db1db 100644 --- a/src/contentLayout/__tests__/contentLayout.test.tsx +++ b/src/contentLayout/__tests__/contentLayout.test.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { render } from '@testing-library/react'; +import { Pagination } from 'antd'; import ContentLayout from '..'; @@ -50,4 +51,50 @@ describe('test contentLayout', () => { '500px' ); }); + test('should support contentLayout default table height', () => { + const { container } = render( + + Header + } + /> + + ); + expect(container.querySelector('.ant-table-body')?.style.maxHeight).toBe( + 'calc(calc(calc(100vh - 96px) - 0px) - 88px)' + ); + }); + test('should support contentLayout small table height', () => { + const { container } = render( + + Header + } + /> + + ); + expect(container.querySelector('.ant-table-body')?.style.maxHeight).toBe( + 'calc(calc(calc(100vh - 96px) - 0px) - 72px)' + ); + }); }); diff --git a/src/contentLayout/components.tsx b/src/contentLayout/components.tsx index 0888a6632..17eab5ca7 100644 --- a/src/contentLayout/components.tsx +++ b/src/contentLayout/components.tsx @@ -16,16 +16,21 @@ type ITableProps = { } & TableProps & Omit; -export const TableLayout = ({ height, ...otherProps }: ITableProps) => { - let lineHeight = 44; +export const TableLayout = ({ height, size, className, ...otherProps }: ITableProps) => { + let lineHeight = size === 'small' ? 36 : 44; if (otherProps.footer) { - lineHeight = lineHeight * 2; + let footerHeight = 44; + if (className?.includes('dt-pagination-small')) footerHeight = 36; + lineHeight = lineHeight + footerHeight; } - const scroll: TableProps['scroll'] = otherProps?.scroll ? { ...otherProps.scroll } : {}; - scroll.y = `calc(${height} - ${lineHeight}px)`; - return ; + const scroll: TableProps['scroll'] = { + y: `calc(${height} - ${lineHeight}px)`, + ...otherProps.scroll, + }; + + return
; }; interface HeaderProps extends ContentLayoutChildProps { @@ -33,10 +38,12 @@ interface HeaderProps extends ContentLayoutChildProps { className?: string; } -export const Header = ({ ref, className, style, children }: HeaderProps) => { - return ( -
- {children} -
- ); -}; +export const Header = React.forwardRef( + ({ className, style, children }, ref) => { + return ( +
+ {children} +
+ ); + } +); diff --git a/src/contentLayout/index.tsx b/src/contentLayout/index.tsx index 049fdf4d2..ad549e3a5 100644 --- a/src/contentLayout/index.tsx +++ b/src/contentLayout/index.tsx @@ -28,12 +28,14 @@ const ContentLayout = (props: IProps) => { Children.forEach(children, (child) => { if (child?.type === Header) { header = cloneElement(child, { + key: 'header', ref: headerRef, }); } if (child?.type === TableLayout) { content.push( cloneElement(child, { + key: 'table', height: contentHeight, }) );