feat(components): [cascader-panel] add empty slot (#16274)

* feat(components): [cascader] add `empty-panel` slot

* chore: update version tag

* chore: update

* feat: rename empty-panel to empty

* chore: format

* test: add test case

* test: update

* Update docs/en-US/component/cascader.md
This commit is contained in:
btea 2024-09-13 09:34:40 +08:00 committed by GitHub
parent 647af2cd22
commit ca677519b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 6 deletions

View File

@ -209,9 +209,10 @@ cascader/panel
### CascaderPanel Slots
| Name | Description | Scope |
| ------- | ---------------------------------------------------------------------------------------------- | ----------------------------------- |
| default | the custom content of cascader node, which are current Node object and node data respectively. | ^[object]`{ node: any, data: any }` |
| Name | Description | Scope |
| -------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------- |
| default | the custom content of cascader node, which are current Node object and node data respectively. | ^[object]`{ node: any, data: any }` |
| empty ^(2.8.3) | the content of the panel when there is no data. | — |
### CascaderPanel Exposes

View File

@ -9,7 +9,11 @@
:ref="(item) => (menuList[index] = item)"
:index="index"
:nodes="[...menu]"
/>
>
<template #empty>
<slot name="empty" />
</template>
</el-cascader-menu>
</div>
</template>

View File

@ -23,7 +23,7 @@
{{ t('el.cascader.loading') }}
</div>
<div v-else-if="isEmpty" :class="ns.e('empty-text')">
{{ t('el.cascader.noData') }}
<slot name="empty">{{ t('el.cascader.noData') }}</slot>
</div>
<svg
v-else-if="panel?.isHoverMenu"

View File

@ -524,4 +524,39 @@ describe('Cascader.vue', () => {
expect(inputEl.style.height).toEqual(`${sizeMap[size] - 2}px`)
}
})
describe('render empty slot', () => {
it('correct render panel empty slot', async () => {
const wrapper = _mount(() => (
<Cascader>
{{
empty: () => <div>-=-empty-=-</div>,
}}
</Cascader>
))
await wrapper.find(TRIGGER).trigger('click')
const emptySlotEl = document.querySelector(
'.el-cascader-menu__empty-text'
)
expect(emptySlotEl?.textContent).toBe('-=-empty-=-')
})
it('correct render menu list empty slot', async () => {
const wrapper = _mount(() => (
<Cascader filterable>
{{
empty: () => <div>-=-empty-=-no-data</div>,
}}
</Cascader>
))
const input = wrapper.find('input')
await input.trigger('focus')
const emptySlotEl = document.querySelector(
'.el-cascader-menu__empty-text'
)
expect(emptySlotEl?.textContent).toBe('-=-empty-=-no-data')
})
})
})

View File

@ -152,7 +152,11 @@
:render-label="$slots.default"
@expand-change="handleExpandChange"
@close="$nextTick(() => togglePopperVisible(false))"
/>
>
<template #empty>
<slot name="empty" />
</template>
</el-cascader-panel>
<el-scrollbar
v-if="filterable"
v-show="filtering"