From 84f53d00143f1813782a45df8c45c3fbca1b9216 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 22 Dec 2019 12:46:26 +0800 Subject: [PATCH] fix(Tag): should not trigger click event when close (#5351) --- src/tag/index.tsx | 5 +++-- src/tag/test/index.spec.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/tag/index.tsx b/src/tag/index.tsx index 2e114d1c9..4ab2d814c 100644 --- a/src/tag/index.tsx +++ b/src/tag/index.tsx @@ -50,12 +50,13 @@ function Tag( class={[bem([classes, type]), { [BORDER_SURROUND]: plain }]} {...inherit(ctx, true)} > - {slots.default && slots.default()} + {slots.default?.()} {props.closeable && ( { + onClick={(event: PointerEvent) => { + event.stopPropagation(); emit(ctx, 'close'); }} /> diff --git a/src/tag/test/index.spec.js b/src/tag/test/index.spec.js index 2fff16cbd..77c3544db 100644 --- a/src/tag/test/index.spec.js +++ b/src/tag/test/index.spec.js @@ -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); +});