From 890936f61d958e8fff526e04f1787f1a6628e9ba Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 21 Sep 2019 07:34:46 +0800 Subject: [PATCH] feat(Search): improve accessibility (#4522) --- src/search/index.tsx | 12 ++++++------ src/search/test/__snapshots__/demo.spec.js.snap | 6 ++---- src/search/test/__snapshots__/index.spec.js.snap | 4 +--- src/search/test/index.spec.js | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) 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
-
+
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('');