feat(DropdownItem): add title slot (#4975)

This commit is contained in:
neverland 2019-11-10 11:47:11 +08:00 committed by GitHub
parent 76cdb03962
commit 9d12e895fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 2 deletions

View File

@ -140,6 +140,13 @@ Use `active-color` prop to custom active color of the title and options
| opened | Triggered when opened menu | - |
| close | Triggered when close menu | - |
### DropdownItem Slots
| Name | Description |
|------|------|
| default | Content |
| title | Custom title |
### DropdownItem Methods
Use ref to get DropdownItem instance and call instance methods

View File

@ -144,6 +144,13 @@ export default {
| opened | 打开菜单栏且动画结束后触发 | - |
| close | 关闭菜单栏时触发 | - |
### DropdownItem Slots
| 名称 | 说明 |
|------|------|
| default | 菜单内容 |
| title | 自定义标题,不支持动态渲染 |
### DropdownItem 方法
通过 ref 可以获取到 DropdownItem 实例并调用实例方法

View File

@ -95,7 +95,7 @@ export default createComponent({
]}
style={{ color: item.showPopup ? this.activeColor : '' }}
>
<div class="van-ellipsis">{item.displayTitle}</div>
<div class="van-ellipsis">{item.slots('title') || item.displayTitle}</div>
</span>
</div>
));

View File

@ -303,6 +303,19 @@ exports[`title prop 1`] = `
</div>
`;
exports[`title slot 1`] = `
<div class="van-dropdown-menu van-hairline--top-bottom">
<div role="button" tabindex="0" class="van-dropdown-menu__item"><span class="van-dropdown-menu__title"><div class="van-ellipsis">
Custom Title
</div></span></div>
<div>
<div class="van-dropdown-item van-dropdown-item--down" style="z-index: 10; top: 0px; display: none;">
<!---->
</div>
</div>
</div>
`;
exports[`toggle method 1`] = `
<div class="van-dropdown-menu van-hairline--top-bottom">
<div role="button" tabindex="0" class="van-dropdown-menu__item"><span class="van-dropdown-menu__title van-dropdown-menu__title--active van-dropdown-menu__title--down"><div class="van-ellipsis"></div></span></div>

View File

@ -241,3 +241,19 @@ test('toggle method', async done => {
}
});
});
test('title slot', () => {
const wrapper = mount({
template: `
<van-dropdown-menu>
<van-dropdown-item>
<template #title>
Custom Title
</template>
</van-dropdown-item>
</van-dropdown-menu>
`
});
expect(wrapper).toMatchSnapshot();
});

View File

@ -221,7 +221,7 @@ export default {
| 名称 | 说明 |
|------|------|
| default | 标签页内容 |
| title | 自定义标 |
| title | 自定义标题,不支持动态渲染 |
### Tabs Events