From 31930e47d8565e2aa43fc6f108f267a73772b4d6 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 23 Dec 2021 20:09:15 +0800 Subject: [PATCH] feat(TabbarItem): add badge-props prop (#10092) --- packages/vant/src/tabbar-item/TabbarItem.tsx | 7 +++++-- packages/vant/src/tabbar/README.md | 1 + packages/vant/src/tabbar/README.zh-CN.md | 1 + packages/vant/src/tabbar/test/index.spec.tsx | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/vant/src/tabbar-item/TabbarItem.tsx b/packages/vant/src/tabbar-item/TabbarItem.tsx index 4fc41da39..f8d3714a8 100644 --- a/packages/vant/src/tabbar-item/TabbarItem.tsx +++ b/packages/vant/src/tabbar-item/TabbarItem.tsx @@ -2,6 +2,7 @@ import { computed, defineComponent, getCurrentInstance, + type PropType, type ExtractPropTypes, } from 'vue'; @@ -15,7 +16,7 @@ import { routeProps, useRoute } from '../composables/use-route'; // Components import { Icon } from '../icon'; -import { Badge } from '../badge'; +import { Badge, type BadgeProps } from '../badge'; const [name, bem] = createNamespace('tabbar-item'); @@ -24,6 +25,7 @@ const tabbarItemProps = extend({}, routeProps, { icon: String, name: numericProp, badge: numericProp, + badgeProps: Object as PropType>, iconPrefix: String, }); @@ -100,8 +102,9 @@ export default defineComponent({
{slots.default?.({ active: active.value })} diff --git a/packages/vant/src/tabbar/README.md b/packages/vant/src/tabbar/README.md index cdcc8e407..c39c200d5 100644 --- a/packages/vant/src/tabbar/README.md +++ b/packages/vant/src/tabbar/README.md @@ -190,6 +190,7 @@ export default { | icon-prefix | Icon className prefix | _string_ | `van-icon` | | dot | Whether to show red dot | _boolean_ | - | | badge | Content of the badge | _number \| string_ | `''` | +| badge-props `v3.2.8` | Props of Badge,see [Badge - props](#/en-US/badge#props) | _BadgeProps_ | - | | url | Link | _string_ | - | | to | Target route of the link, same as to of vue-router | _string \| object_ | - | | replace | If true, the navigation will not leave a history record | _boolean_ | `false` | diff --git a/packages/vant/src/tabbar/README.zh-CN.md b/packages/vant/src/tabbar/README.zh-CN.md index 404c115cb..396b1f703 100644 --- a/packages/vant/src/tabbar/README.zh-CN.md +++ b/packages/vant/src/tabbar/README.zh-CN.md @@ -202,6 +202,7 @@ export default { | icon-prefix | 图标类名前缀,等同于 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` | | dot | 是否显示图标右上角小红点 | _boolean_ | `false` | | badge | 图标右上角徽标的内容 | _number \| string_ | - | +| badge-props `v3.2.8` | 自定义徽标的属性,传入的对象会被透传给 [Badge 组件的 props](#/zh-CN/badge#props) | _BadgeProps_ | - | | url | 点击后跳转的链接地址 | _string_ | - | | to | 点击后跳转的目标路由对象,等同于 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | _string \| object_ | - | | replace | 是否在跳转时替换当前页面历史 | _boolean_ | `false` | diff --git a/packages/vant/src/tabbar/test/index.spec.tsx b/packages/vant/src/tabbar/test/index.spec.tsx index 7d422e991..944405f76 100644 --- a/packages/vant/src/tabbar/test/index.spec.tsx +++ b/packages/vant/src/tabbar/test/index.spec.tsx @@ -199,3 +199,21 @@ test('should render placeholder element when using placeholder prop', async () = expect(wrapper.html()).toMatchSnapshot(); restore(); }); + +test('should render badge-props prop correctly', async () => { + const wrapper = mount({ + render() { + return ( + + + Tab + + + ); + }, + }); + + await nextTick(); + const badge = wrapper.find('.van-badge'); + expect(badge.style.backgroundColor).toEqual('blue'); +});