feat(Tabs): add rendered prop (#5315)

This commit is contained in:
neverland 2019-12-19 17:16:33 +08:00 committed by GitHub
parent 329a5cd0c3
commit 80834d7400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 15 deletions

View File

@ -1,4 +1,4 @@
name: Node CI
name: CI
on: [push, pull_request]

View File

@ -223,12 +223,13 @@ In scrollspy mode, the list of content will be tiled
### Tabs Events
| Event | Description | Arguments |
|------|------|------|
| click | Triggered when click tab | namename of current tabtitle: tab title |
| change | Triggered when active tab changed | namename of current tabtitle: tab title |
| disabled | Triggered when click disabled tab | namename of current tab, title: tab title |
| scroll | Triggered when tab scroll in sticky mode | object: { scrollTop, isFixed } |
| Event | Description | Arguments | Version |
|------|------|------|------|
| click | Triggered when click tab | nametitle | - |
| change | Triggered when active tab changed | nametitle | - |
| disabled | Triggered when click disabled tab | nametitle | - |
| rendered | Triggered when content first rendered in lazy-render mode | nametitle | 2.3.0 |
| scroll | Triggered when tab scroll in sticky mode | object: { scrollTop, isFixed } | - |
### Tabs Methods

View File

@ -208,7 +208,7 @@ export default {
| ellipsis | 是否省略过长的标题文字 | *boolean* | `true` | - |
| sticky | 是否使用粘性定位布局 | *boolean* | `false` | - |
| swipeable | 是否开启手势滑动切换 | *boolean* | `false` | - |
| lazy-render | 是否开启标签页内容延迟渲染 | *boolean* | `true` | - |
| lazy-render | 是否开启延迟渲染(首次切换到标签时才触发内容渲染) | *boolean* | `true` | - |
| scrollspy | 是否开启滚动导航 | *boolean* | `false` | 2.3.0 |
### Tab Props
@ -227,12 +227,13 @@ export default {
### Tabs Events
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| click | 点击标签时触发 | name标签标识符title标题 |
| change | 当前激活的标签改变时触发 | name标签标识符title标题 |
| disabled | 点击被禁用的标签时触发 | name标签标识符title标题 |
| scroll | 滚动时触发,仅在 sticky 模式下生效 | { scrollTop: 距离顶部位置, isFixed: 是否吸顶 } |
| 事件名 | 说明 | 回调参数 | 版本 |
|------|------|------|------|
| click | 点击标签时触发 | name标识符title标题 | - |
| change | 当前激活的标签改变时触发 | name标识符title标题 | - |
| disabled | 点击被禁用的标签时触发 | name标识符title标题 | - |
| rendered | 标签内容首次渲染时触发(仅在开启延迟渲染后触发) | name标识符title标题 | 2.3.0 |
| scroll | 滚动时触发,仅在 sticky 模式下生效 | { scrollTop: 距离顶部位置, isFixed: 是否吸顶 } | - |
### Tabs 方法

View File

@ -162,7 +162,7 @@ export default {
@import '../../style/var';
.demo-tab {
margin-bottom: 300px;
margin-bottom: 80vh;
.van-tab .van-icon {
margin-right: 5px;

View File

@ -41,6 +41,12 @@ export default createComponent({
title() {
this.parent.setLine();
},
inited(val) {
if (this.parent.lazyRender && val) {
this.parent.$emit('rendered', this.computedName, this.title);
}
}
},

View File

@ -293,3 +293,49 @@ test('scrollspy', async () => {
expect(wrapper).toMatchSnapshot();
expect(onChange).toHaveBeenCalledWith('c', 'title3');
});
test('rendered event', () => {
const onRendered = jest.fn();
const wrapper = mount({
template: `
<van-tabs v-model="active" @rendered="onRendered">
<van-tab name="a" title="title1">Text</van-tab>
<van-tab name="b" title="title2">Title2</van-tab>
</van-tabs>
`,
data() {
return {
active: 'a'
};
},
methods: {
onRendered
}
});
expect(onRendered).toHaveBeenCalledWith('a', 'title1');
const tabs = wrapper.findAll('.van-tab');
tabs.at(1).trigger('click');
tabs.at(0).trigger('click');
expect(onRendered).toHaveBeenCalledTimes(2);
});
test('should not trigger rendered event when disable lazy-render', () => {
const onRendered = jest.fn();
mount({
template: `
<van-tabs :lazy-render="false" @rendered="onRendered">
<van-tab>Text</van-tab>
<van-tab>Title2</van-tab>
</van-tabs>
`,
methods: {
onRendered
}
});
expect(onRendered).toHaveBeenCalledTimes(0);
});