Skip to content

Commit

Permalink
Merge pull request #11436 from ranwawa/docs/table-fill-height
Browse files Browse the repository at this point in the history
补充tableFillHeight文档和单测
  • Loading branch information
hsm-lv authored Dec 30, 2024
2 parents a756a28 + 7076c4d commit 2747fee
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
43 changes: 43 additions & 0 deletions packages/amis/__tests__/renderers/Table/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import {render, screen} from '@testing-library/react';

import {render as amisRender} from '../../../src';

describe('Table tableFillHeight', () => {
const renderTable = (autoFillHeight = false, rows = [] as any) => {
return render(
amisRender({
type: 'page',
data: {
rows
},
body: {
type: 'table',
autoFillHeight,
source: '${rows}'
}
})
);
};

it('autoFillHeight未开启,table元素高度根据内容撑开', () => {
const {container} = renderTable();
expect(
container.querySelector('.cxd-Table-table--tableFillHeight')
).toBeNull();
});

it('autoFillHeight开启,表格有数据,table元素高度根据内容撑开', () => {
const {container} = renderTable(true, [{id: 1}]);
expect(
container.querySelector('.cxd-Table-table--tableFillHeight')
).toBeNull();
});

it('autoFillHeight开启,表格无数据,table元素高度根据父元素撑开', () => {
const {container} = renderTable(true, []);
expect(
container.querySelector('.cxd-Table-table--tableFillHeight')
).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2806,7 +2806,6 @@ export default class Table<
const {
classnames: cx,
tableClassName,
tableFillHeight,
store,
placeholder,
render,
Expand Down Expand Up @@ -2848,7 +2847,8 @@ export default class Table<
'Table-table--withCombine': store.combineNum > 0,
'Table-table--affixHeader':
affixHeader && !autoFillHeight && store.columnWidthReady,
'Table-table--tableFillHeight': autoFillHeight && tableFillHeight
'Table-table--tableFillHeight':
autoFillHeight && !store.items.length
},
tableClassName
)}
Expand Down

0 comments on commit 2747fee

Please sign in to comment.