fix(Tag): should not trigger click event when close (#5351)

This commit is contained in:
neverland 2019-12-22 12:46:26 +08:00 committed by GitHub
parent cd6050d3e4
commit 84f53d0014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -50,12 +50,13 @@ function Tag(
class={[bem([classes, type]), { [BORDER_SURROUND]: plain }]}
{...inherit(ctx, true)}
>
{slots.default && slots.default()}
{slots.default?.()}
{props.closeable && (
<Icon
name="cross"
class={bem('close')}
onClick={() => {
onClick={(event: PointerEvent) => {
event.stopPropagation();
emit(ctx, 'close');
}}
/>

View File

@ -31,3 +31,24 @@ test('close event', () => {
wrapper.find('.van-tag__close').trigger('click');
expect(close).toHaveBeenCalledTimes(1);
});
test('should not trigger click event when close', () => {
const close = jest.fn();
const click = jest.fn();
const wrapper = mount(Tag, {
propsData: {
closeable: true
},
context: {
on: {
close,
click
}
}
});
wrapper.find('.van-tag__close').trigger('click');
expect(close).toHaveBeenCalledTimes(1);
expect(click).toHaveBeenCalledTimes(0);
});