feat(SidebarItem): add title slot (#7220)

This commit is contained in:
JSparow 2020-09-21 21:29:09 +08:00 committed by GitHub
parent f609c224b1
commit e201bc55ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 1 deletions

View File

@ -43,7 +43,7 @@ export default createComponent({
onClick={this.onClick}
>
<div class={bem('text')}>
{this.title}
{this.slots('title') ?? this.title}
<Info
dot={this.dot}
info={this.badge ?? this.info}

View File

@ -110,3 +110,9 @@ export default {
| Event | Description | Arguments |
| ----- | ------------------------- | ---------------------------- |
| click | Triggered when click item | index: index of current item |
### SidebarItem Slots
| Name | Description |
| ----- | ---------------- |
| title | Custom item title |

View File

@ -119,3 +119,9 @@ export default {
| 事件名 | 说明 | 回调参数 |
| ------ | ---------- | ----------------------- |
| click | 点击时触发 | index: 当前导航项的索引 |
### SidebarItem Slots
| Name | Description |
| ----- | ----------- |
| title | 自定义标题 |

View File

@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`title slot 1`] = `
<div class="van-sidebar"><a class="van-sidebar-item van-sidebar-item--select">
<div class="van-sidebar-item__text">Title Slot
<!---->
</div>
</a></div>
`;

View File

@ -76,3 +76,22 @@ test('without parent', () => {
expect(err).toBeTruthy();
}
});
test('title slot', () => {
const wrapper = mount({
template: `
<van-sidebar v-model="active">
<van-sidebar-item>
<template #title>Title Slot</template>
</van-sidebar-item>
</van-sidebar>
`,
data() {
return {
active: 0,
};
},
});
expect(wrapper).toMatchSnapshot();
});