fix(components): [el-table] render failed when custom table column (#6398)

This commit is contained in:
msidolphin 2022-03-06 18:01:40 +08:00 committed by GitHub
parent a4679050ea
commit 333b1b450a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 4 deletions

View File

@ -803,6 +803,45 @@ describe('table column', () => {
wrapper.find('.hidden-columns').find('.other-component').exists()
).toBeFalsy()
})
it('should not rendered text in hidden-columns', async () => {
const TableColumn = {
name: 'TableColumn',
components: {
ElTableColumn,
},
template: `
<el-table-column>
<template v-if="$slots.default" #default="scope">
<slot v-bind="scope" />
</template>
</el-table-column>
`,
}
const wrapper = mount({
components: {
ElTableColumn,
ElTable,
TableColumn,
},
template: `
<el-table :data="testData">
<table-column>
<template #default="{ row }">Hello World</template>
</table-column>
</el-table>
`,
data() {
return {
testData: getTestData(),
}
},
})
await doubleWait()
expect(wrapper.find('.hidden-columns').text().trim()).not.toContain(
'Hello World'
)
})
})
describe('dynamic column attribtes', () => {

View File

@ -10,6 +10,7 @@ import {
Fragment,
} from 'vue'
import ElCheckbox from '@element-plus/components/checkbox'
import { isString } from '@element-plus/utils'
import { cellStarts } from '../config'
import { mergeOptions, compose } from '../util'
import useWatcher from './watcher-helper'
@ -156,13 +157,13 @@ export default defineComponent({
return
},
render() {
let children = []
try {
const renderDefault = this.$slots.default?.({
row: {},
column: {},
$index: -1,
})
const children = []
if (renderDefault instanceof Array) {
for (const childNode of renderDefault) {
if (
@ -174,13 +175,19 @@ export default defineComponent({
childNode.type === Fragment &&
childNode.children instanceof Array
) {
children.push(...childNode.children)
childNode.children.forEach((vnode) => {
// No rendering when vnode is dynamic slot or text
if (vnode?.patchFlag !== 1024 && !isString(vnode?.children)) {
children.push(vnode)
}
})
}
}
}
const vnode = h('div', children)
return vnode
} catch {
children = []
return h('div', [])
}
return h('div', children)
},
})