fix(descriptions): correct calculation of last item's span in useRow hook (#52410)

fix(descriptions): correct calculation of last item's span in useRow hook
This commit is contained in:
合木 2025-01-17 11:12:15 +08:00 committed by GitHub
parent 357dd53f85
commit 88d81e541f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -102,6 +102,20 @@ describe('Descriptions', () => {
expect(container.querySelectorAll('.ant-descriptions-item')[6]).toHaveAttribute('colSpan', '2');
});
it('when column=6, last item span should be 5', () => {
const { container } = render(
<Descriptions
column={6}
items={[
{ label: '0', children: '' },
{ label: '1', children: '', span: 2 },
]}
/>,
);
expect(container.querySelectorAll('.ant-descriptions-item')[0]).toHaveAttribute('colSpan', '1');
expect(container.querySelectorAll('.ant-descriptions-item')[1]).toHaveAttribute('colSpan', '5');
});
it('column is number', () => {
const wrapper = render(
<Descriptions column={3}>

View File

@ -53,7 +53,7 @@ function getCalcRows(
if (count < mergedColumn) {
// If the span of the last element in the current row is less than the column, then add its span to the remaining columns
const last = rows[rows.length - 1];
last.span = mergedColumn - count + 1;
last.span = mergedColumn - (count - (last.span || 1));
return rows;
}
return rows;