fix: virtual table display error (#50737)

This commit is contained in:
huiliangShen 2024-09-06 15:46:39 +08:00 committed by GitHub
parent ba023f5849
commit 89f55f2985
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 116 additions and 4 deletions

View File

@ -43,4 +43,111 @@ describe('Table.Virtual', () => {
expect(errSpy).toHaveBeenCalledWith('Warning: `scroll.y` in virtual table must be number.');
errSpy.mockRestore();
});
it('should work with edit cell', () => {
const EditableRow: React.FC = ({ ...props }) => <tr {...props} />;
const EditableCell: React.FC<React.PropsWithChildren<any>> = ({ children, ...restProps }) => (
<td {...restProps}>{children}</td>
);
const components = {
body: {
row: EditableRow,
cell: EditableCell,
},
};
const { container } = render(
<Table
virtual
components={components}
scroll={{ y: 100 }}
columns={[
{
dataIndex: 'key',
},
]}
dataSource={[
{
key: 'bamboo',
},
]}
/>,
);
expect(
container.querySelectorAll('.ant-table-wrapper .ant-table-tbody-virtual .ant-table-row'),
).toHaveLength(1);
expect(
container.querySelectorAll('.ant-table-tbody-virtual-holder .ant-table-cell'),
).toHaveLength(1);
expect(
container.querySelector('.ant-table-tbody-virtual-holder .ant-table-cell')?.textContent,
).toEqual('bamboo');
const styleMap = getComputedStyle(
container.querySelector<HTMLElement>(
'.ant-table-wrapper .ant-table-tbody-virtual .ant-table-row',
)!,
);
expect(styleMap.display).toEqual('flex');
});
it('should work with sub table', () => {
const expandedRowRender = () => {
const columns = [
{ title: 'Date', dataIndex: 'date', key: 'date' },
{ title: 'Name', dataIndex: 'name', key: 'name' },
{ title: 'Upgrade Status', dataIndex: 'upgradeNum', key: 'upgradeNum' },
];
const data = [];
for (let i = 0; i < 3; ++i) {
data.push({
key: i.toString(),
date: '2014-12-24 23:12:00',
name: 'This is production name',
upgradeNum: 'Upgraded: 56',
});
}
return <Table columns={columns} dataSource={data} pagination={false} />;
};
const { container } = render(
<Table
columns={[
{
dataIndex: 'key',
},
]}
expandable={{ expandedRowRender, defaultExpandedRowKeys: ['0'] }}
dataSource={[
{
key: '0',
},
]}
size="middle"
virtual
scroll={{ y: 200 }}
/>,
);
expect(
container.querySelectorAll('.ant-table-tbody-virtual-holder-inner > div > .ant-table-row'),
).toHaveLength(1);
expect(
container.querySelectorAll(
'.ant-table-tbody-virtual-holder-inner > div > .ant-table-row > .ant-table-cell',
)?.[1]?.textContent,
).toEqual('0');
expect(
container.querySelectorAll('.ant-table-tbody-virtual-holder .ant-table-expanded-row'),
).toHaveLength(1);
const styleMap = getComputedStyle(
container.querySelector<HTMLElement>(
'.ant-table-tbody-virtual-holder .ant-table-expanded-row .ant-table-row',
)!,
);
expect(styleMap.display).toEqual('table-row');
});
});

View File

@ -15,10 +15,15 @@ const genVirtualStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
[`${componentCls}-wrapper`]: {
// ========================== Row ==========================
[`${componentCls}-tbody-virtual`]: {
[`${componentCls}-row:not(tr)`]: {
display: 'flex',
boxSizing: 'border-box',
width: '100%',
[`${componentCls}-tbody-virtual-holder-inner`]: {
[`
& > ${componentCls}-row,
& > div:not(${componentCls}-row) > ${componentCls}-row
`]: {
display: 'flex',
boxSizing: 'border-box',
width: '100%',
},
},
[`${componentCls}-cell`]: {