From d944b9fd584c9810dc7e6a0586feced14b17c2de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E6=9C=A8?= Date: Wed, 15 Jan 2025 11:29:34 +0800 Subject: [PATCH] test(descriptions): add test for last item span when column is 6 fix(descriptions): correct calculation of last item's span in useRow hook --- components/descriptions/__tests__/index.test.tsx | 14 ++++++++++++++ components/descriptions/hooks/useRow.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/descriptions/__tests__/index.test.tsx b/components/descriptions/__tests__/index.test.tsx index c273b1171b7e..facd33391ac5 100644 --- a/components/descriptions/__tests__/index.test.tsx +++ b/components/descriptions/__tests__/index.test.tsx @@ -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( + , + ); + 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( diff --git a/components/descriptions/hooks/useRow.ts b/components/descriptions/hooks/useRow.ts index 84945487f441..0cd1d3d6f0f9 100644 --- a/components/descriptions/hooks/useRow.ts +++ b/components/descriptions/hooks/useRow.ts @@ -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;