Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: virtual table display error #50737

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions components/table/__tests__/Table.virtual.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
13 changes: 9 additions & 4 deletions components/table/style/virtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`]: {
Expand Down
Loading