mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Tag): should not trigger click event when close (#5351)
This commit is contained in:
parent
cd6050d3e4
commit
84f53d0014
@ -50,12 +50,13 @@ function Tag(
|
|||||||
class={[bem([classes, type]), { [BORDER_SURROUND]: plain }]}
|
class={[bem([classes, type]), { [BORDER_SURROUND]: plain }]}
|
||||||
{...inherit(ctx, true)}
|
{...inherit(ctx, true)}
|
||||||
>
|
>
|
||||||
{slots.default && slots.default()}
|
{slots.default?.()}
|
||||||
{props.closeable && (
|
{props.closeable && (
|
||||||
<Icon
|
<Icon
|
||||||
name="cross"
|
name="cross"
|
||||||
class={bem('close')}
|
class={bem('close')}
|
||||||
onClick={() => {
|
onClick={(event: PointerEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
emit(ctx, 'close');
|
emit(ctx, 'close');
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -31,3 +31,24 @@ test('close event', () => {
|
|||||||
wrapper.find('.van-tag__close').trigger('click');
|
wrapper.find('.van-tag__close').trigger('click');
|
||||||
expect(close).toHaveBeenCalledTimes(1);
|
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);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user