fix(components): [date-picker] filter custom content comment (#4651)

This commit is contained in:
btea 2021-12-10 22:35:47 -06:00 committed by GitHub
parent 4f6cac4252
commit 81efc44c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 15 deletions

View File

@ -275,6 +275,54 @@ describe('DatePicker', () => {
).toBeTruthy()
})
it('custom content comment', async () => {
_mount(
`<el-date-picker
v-model="value"
ref="input">
<template #default="{ isCurrent, text }">
<!-- <div class="cell" :class="{ current: isCurrent }">
<div>{{ text + "csw" }}</div>
</div> -->
</template>
</el-date-picker>`,
() => ({ value: '' }),
{
mounted() {
this.$refs.input.focus()
},
}
)
await nextTick()
const el = document.querySelector('td.available .el-date-table-cell')
const text = el.textContent
expect(text.includes('csw')).toBeFalsy()
})
it('custom content value validate', async () => {
_mount(
`<el-date-picker
v-model="value"
ref="input">
<template #default="{ isCurrent, text }">
<div class="cell" :class="{ current: isCurrent }">
<div>{{ text + "csw" }}</div>
</div>
</template>
</el-date-picker>`,
() => ({ value: '' }),
{
mounted() {
this.$refs.input.focus()
},
}
)
await nextTick()
const el = document.querySelector('td.available .cell')
const text = el.textContent
expect(text.includes('csw')).toBeTruthy()
})
describe('value-format', () => {
it('with literal string', async () => {
const day = dayjs()

View File

@ -14,23 +14,29 @@ export default defineComponent({
const picker = inject(ROOT_PICKER_INJECTION_KEY)
return () => {
const cell = props.cell
return picker?.ctx.slots.default
? picker.ctx.slots.default(cell)
: h(
'div',
if (picker?.ctx.slots.default) {
const list = picker.ctx.slots.default(cell).filter((item) => {
return item.type.toString() !== 'Symbol(Comment)'
})
if (list.length) {
return list
}
}
return h(
'div',
{
class: 'el-date-table-cell',
},
[
h(
'span',
{
class: 'el-date-table-cell',
class: 'el-date-table-cell__text',
},
[
h(
'span',
{
class: 'el-date-table-cell__text',
},
[cell?.text]
),
]
)
[cell?.text]
),
]
)
}
},
})