From d76567eeec28a6117213773704fc098fb59e97cb Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 5 Mar 2021 15:33:17 +0800 Subject: [PATCH] fix(Swipe): should render dynamic swipe item correctly (#8288) --- src/swipe/index.tsx | 9 ++--- .../test/__snapshots__/index.spec.js.snap | 38 +++++++++++++++++++ src/swipe/test/index.spec.js | 31 +++++++++++++++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/swipe/index.tsx b/src/swipe/index.tsx index d69fbc1e7..caf4722da 100644 --- a/src/swipe/index.tsx +++ b/src/swipe/index.tsx @@ -282,7 +282,9 @@ export default createComponent({ const rect = useRect(root); - active = Math.min(children.length - 1, active); + if (count.value) { + active = Math.min(count.value - 1, active); + } state.rect = rect; state.swiping = true; @@ -430,10 +432,7 @@ export default createComponent({ (value) => initialize(+value) ); - watch( - () => children.length, - () => initialize(state.active) - ); + watch(count, () => initialize(state.active)); watch( () => props.autoplay, diff --git a/src/swipe/test/__snapshots__/index.spec.js.snap b/src/swipe/test/__snapshots__/index.spec.js.snap index 7a762ba3b..68f97cce8 100644 --- a/src/swipe/test/__snapshots__/index.spec.js.snap +++ b/src/swipe/test/__snapshots__/index.spec.js.snap @@ -32,6 +32,44 @@ exports[`should not allow to drag swipe when touchable is false 1`] = ` `; +exports[`should render dynamic SwipeItem correctly 1`] = ` +
+
+
+
+`; + +exports[`should render dynamic SwipeItem correctly 2`] = ` +
+
+
+ + 1 + +
+
+ + 2 + +
+
+
+ + + + +
+
+`; + exports[`should render initial swipe correctly 1`] = `
{ + const wrapper = mount({ + setup() { + const render = ref(false); + onMounted(() => { + render.value = true; + }); + return { render }; + }, + render() { + return ( + + {this.render && [ + + 1 + , + + 2 + , + ]} + + ); + }, + }); + + expect(wrapper.html()).toMatchSnapshot(); + await later(); + expect(wrapper.html()).toMatchSnapshot(); +});