fix(descriptions): fix the last td colspan (#2567)

re #2559
This commit is contained in:
kooriookami 2021-07-19 20:15:24 +08:00 committed by GitHub
parent 4ffb2d164c
commit a0e5776ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -134,10 +134,12 @@ describe('Descriptions.vue', () => {
<el-descriptions-item label="1">1</el-descriptions-item>
<el-descriptions-item label="2" :span="2">2</el-descriptions-item>
<el-descriptions-item label="3">3</el-descriptions-item>
<el-descriptions-item label="4">4</el-descriptions-item>
</el-descriptions>
`)
expect(wrapper.findAll('td')[1].element.getAttribute('colSpan')).toEqual('2')
expect(wrapper.findAll('td')[3].element.getAttribute('colSpan')).toEqual('2')
})
test('re-rendered when slots is updated', async () => {

View File

@ -90,8 +90,8 @@ export default defineComponent({
node.props.span = count
}
if (isLast) {
// set the max span, cause of the last td
node.props.span = props.column
// set the last span
node.props.span = span
}
return node
}
@ -101,12 +101,19 @@ export default defineComponent({
const rows = []
let temp = []
let count = props.column
let totalSpan = 0 // all spans number of item
children.forEach((node, index) => {
const span = node.props?.span || 1
let span = node.props?.span || 1
if (index < children.length - 1) {
totalSpan += span > count ? count : span
}
if (index === children.length - 1) {
temp.push(filledNode(node, span, count, true))
// calculate the last item span
const lastSpan = props.column - totalSpan % props.column
temp.push(filledNode(node, lastSpan, count, true))
rows.push(temp)
return
}