From 92fb70d6e891e893ae4c2772b8d12958e1b84e13 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 18 Dec 2021 08:32:57 +0800 Subject: [PATCH] feat(Swipe): indicator slot add total param (#10060) * feat(Swipe): indicator slot add total param * test: indicator slot --- packages/vant/src/swipe/README.md | 8 +++---- packages/vant/src/swipe/README.zh-CN.md | 8 +++---- packages/vant/src/swipe/Swipe.tsx | 1 + .../test/__snapshots__/index.spec.js.snap | 22 +++++++++++++++++++ packages/vant/src/swipe/test/index.spec.js | 22 +++++++++++++++++++ 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/packages/vant/src/swipe/README.md b/packages/vant/src/swipe/README.md index 4b93268af..54076e953 100644 --- a/packages/vant/src/swipe/README.md +++ b/packages/vant/src/swipe/README.md @@ -206,10 +206,10 @@ swipeRef.value?.next(); ### Swipe Slots -| Name | Description | SlotProps | -| ------------------- | ---------------- | -------------------- | -| default | Content | - | -| indicator `v3.0.16` | Custom indicator | _{ active: number }_ | +| Name | Description | SlotProps | +| ------------------ | ---------------- | ----------------------------------- | +| default | Content | - | +| indicator `v3.3.8` | Custom indicator | _{ active: number, total: number }_ | ## Theming diff --git a/packages/vant/src/swipe/README.zh-CN.md b/packages/vant/src/swipe/README.zh-CN.md index 43abd9e4c..98636d516 100644 --- a/packages/vant/src/swipe/README.zh-CN.md +++ b/packages/vant/src/swipe/README.zh-CN.md @@ -214,10 +214,10 @@ swipeRef.value?.next(); ### Swipe Slots -| 名称 | 说明 | 参数 | -| ------------------- | ------------ | -------------------- | -| default | 轮播内容 | - | -| indicator `v3.0.16` | 自定义指示器 | _{ active: number }_ | +| 名称 | 说明 | 参数 | +| ------------------ | ------------ | ----------------------------------- | +| default | 轮播内容 | - | +| indicator `v3.3.8` | 自定义指示器 | _{ active: number, total: number }_ | ## 主题定制 diff --git a/packages/vant/src/swipe/Swipe.tsx b/packages/vant/src/swipe/Swipe.tsx index 3fd156f9d..564fd277a 100644 --- a/packages/vant/src/swipe/Swipe.tsx +++ b/packages/vant/src/swipe/Swipe.tsx @@ -384,6 +384,7 @@ export default defineComponent({ if (slots.indicator) { return slots.indicator({ active: activeIndicator.value, + total: count.value, }); } if (props.showIndicators && count.value > 1) { diff --git a/packages/vant/src/swipe/test/__snapshots__/index.spec.js.snap b/packages/vant/src/swipe/test/__snapshots__/index.spec.js.snap index 729711266..e09105ee3 100644 --- a/packages/vant/src/swipe/test/__snapshots__/index.spec.js.snap +++ b/packages/vant/src/swipe/test/__snapshots__/index.spec.js.snap @@ -76,6 +76,28 @@ exports[`should render dynamic SwipeItem correctly 2`] = ` `; +exports[`should render indicator slot correctly 1`] = ` +
+
+
+ 1 +
+
+ 2 +
+
+ active: 0, total: 2 +
+`; + exports[`should render initial swipe correctly 1`] = `
{ await later(); expect(wrapper.html()).toMatchSnapshot(); }); + +test('should render indicator slot correctly', async () => { + const wrapper = mount({ + render() { + return ( + + `active: ${active}, total: ${total}`, + }} + style={swipeStyle} + > + 1 + 2 + + ); + }, + }); + + await later(); + expect(wrapper.html()).toMatchSnapshot(); +});