mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-11-30 18:27:40 +08:00
fix(components): [el-table] render failed when custom table column (#6398)
This commit is contained in:
parent
a4679050ea
commit
333b1b450a
@ -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', () => {
|
||||
|
@ -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)
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user