From c7aebbe6868a99986714275aee6f9ff269e72ffa Mon Sep 17 00:00:00 2001 From: rex Date: Sun, 29 Nov 2020 19:45:51 +0800 Subject: [PATCH] feat(tabbar): add new props placeholder & icon-prefix (#3792) fix #3445 --- packages/tabbar-item/index.ts | 23 +++++++++++++++++------ packages/tabbar-item/index.wxml | 8 +++----- packages/tabbar/README.md | 2 ++ packages/tabbar/index.ts | 31 +++++++++++++++++++++---------- packages/tabbar/index.wxml | 4 +++- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/packages/tabbar-item/index.ts b/packages/tabbar-item/index.ts index 9778f987..84b67bb7 100644 --- a/packages/tabbar-item/index.ts +++ b/packages/tabbar-item/index.ts @@ -6,6 +6,10 @@ VantComponent({ name: null, icon: String, dot: Boolean, + iconPrefix: { + type: String, + value: 'van-icon', + }, }, relation: { @@ -20,9 +24,16 @@ VantComponent({ methods: { onClick() { - if (this.parent) { - this.parent.onChange(this); + const { parent } = this; + if (parent) { + const index = parent.children.indexOf(this); + const active = this.data.name || index; + + if (active !== this.data.active) { + parent.$emit('change', active); + } } + this.$emit('click'); }, @@ -36,7 +47,7 @@ VantComponent({ const parentData = parent.data; const { data } = this; const active = (data.name || index) === parentData.active; - const patch: { [key: string]: any } = {}; + const patch: Record = {}; if (active !== data.active) { patch.active = active; @@ -48,9 +59,9 @@ VantComponent({ patch.inactiveColor = parentData.inactiveColor; } - return Object.keys(patch).length > 0 - ? this.set(patch) - : Promise.resolve(); + if (Object.keys(patch).length > 0) { + this.setData(patch); + } }, }, }); diff --git a/packages/tabbar-item/index.wxml b/packages/tabbar-item/index.wxml index d83b061f..524728f3 100644 --- a/packages/tabbar-item/index.wxml +++ b/packages/tabbar-item/index.wxml @@ -3,19 +3,17 @@ - + child.updateFromParent()) - ); + children.forEach((child: TrivialInstance) => child.updateFromParent()); }, - onChange(child: TrivialInstance) { - const index = this.children.indexOf(child); - const active = child.data.name || index; - - if (active !== this.data.active) { - this.$emit('change', active); + setHeight() { + if (!this.data.fixed || !this.data.placeholder) { + return; } + + wx.nextTick(() => { + getRect.call(this, '.van-tabbar').then((res) => { + this.setData({ height: res.height }); + }); + }); }, }, }); diff --git a/packages/tabbar/index.wxml b/packages/tabbar/index.wxml index c49b9d98..43bb1111 100644 --- a/packages/tabbar/index.wxml +++ b/packages/tabbar/index.wxml @@ -1,8 +1,10 @@ + +