diff --git a/src/search/index.tsx b/src/search/index.tsx
index eda6a05de..decc48b4d 100644
--- a/src/search/index.tsx
+++ b/src/search/index.tsx
@@ -53,17 +53,17 @@ function Search(
}
function onCancel() {
+ if (slots.action) {
+ return;
+ }
+
emit(ctx, 'input', '');
emit(ctx, 'cancel');
}
return (
-
- {slots.action ? (
- slots.action()
- ) : (
-
{props.actionText || t('cancel')}
- )}
+
+ {slots.action ? slots.action() : props.actionText || t('cancel')}
);
}
diff --git a/src/search/test/__snapshots__/demo.spec.js.snap b/src/search/test/__snapshots__/demo.spec.js.snap
index 38da8d0b1..34977e7c3 100644
--- a/src/search/test/__snapshots__/demo.spec.js.snap
+++ b/src/search/test/__snapshots__/demo.spec.js.snap
@@ -27,9 +27,7 @@ exports[`renders demo correctly 1`] = `
-
+ 取消
@@ -45,7 +43,7 @@ exports[`renders demo correctly 1`] = `
-
diff --git a/src/search/test/__snapshots__/index.spec.js.snap b/src/search/test/__snapshots__/index.spec.js.snap
index 7d722b2c2..6ce6f0752 100644
--- a/src/search/test/__snapshots__/index.spec.js.snap
+++ b/src/search/test/__snapshots__/index.spec.js.snap
@@ -11,9 +11,7 @@ exports[`action-text prop 1`] = `
-
+ Custom Text
`;
diff --git a/src/search/test/index.spec.js b/src/search/test/index.spec.js
index 3693a8427..884cabe4c 100644
--- a/src/search/test/index.spec.js
+++ b/src/search/test/index.spec.js
@@ -35,7 +35,7 @@ test('cancel event', () => {
}
});
- const cancel = wrapper.find('.van-search__action div');
+ const cancel = wrapper.find('.van-search__action');
cancel.trigger('click');
expect(onInput).toHaveBeenCalledWith('');