Skip to content

Commit

Permalink
feat(Search): improve accessibility (#4522)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Sep 20, 2019
1 parent a1ac34b commit 890936f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/search/index.tsx
Expand Up @@ -53,17 +53,17 @@ function Search(
}

function onCancel() {
if (slots.action) {
return;
}

emit(ctx, 'input', '');
emit(ctx, 'cancel');
}

return (
<div class={bem('action')}>
{slots.action ? (
slots.action()
) : (
<div onClick={onCancel}>{props.actionText || t('cancel')}</div>
)}
<div class={bem('action')} role="button" tabindex="0" onClick={onCancel}>
{slots.action ? slots.action() : props.actionText || t('cancel')}
</div>
);
}
Expand Down
6 changes: 2 additions & 4 deletions src/search/test/__snapshots__/demo.spec.js.snap
Expand Up @@ -27,9 +27,7 @@ exports[`renders demo correctly 1`] = `
</div>
</div>
</div>
<div class="van-search__action">
<div>取消</div>
</div>
<div role="button" tabindex="0" class="van-search__action">取消</div>
</div>
</form>
</div>
Expand All @@ -45,7 +43,7 @@ exports[`renders demo correctly 1`] = `
</div>
</div>
</div>
<div class="van-search__action">
<div role="button" tabindex="0" class="van-search__action">
<div>搜索</div>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/search/test/__snapshots__/index.spec.js.snap
Expand Up @@ -11,9 +11,7 @@ exports[`action-text prop 1`] = `
</div>
</div>
</div>
<div class="van-search__action">
<div>Custom Text</div>
</div>
<div role="button" tabindex="0" class="van-search__action">Custom Text</div>
</div>
`;
Expand Down
2 changes: 1 addition & 1 deletion src/search/test/index.spec.js
Expand Up @@ -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('');
Expand Down

0 comments on commit 890936f

Please sign in to comment.