mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Card: add click event params (#3780)
This commit is contained in:
parent
abc555dd72
commit
701446ece8
@ -80,8 +80,8 @@ Use slot to custom content.
|
|||||||
|
|
||||||
| Event | Description | Arguments |
|
| Event | Description | Arguments |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| click | Triggered when clicked | - |
|
| click | Triggered when clicked | event: Event |
|
||||||
| click-thumb | Triggered when thumb clicked | - |
|
| click-thumb | Triggered when thumb clicked | event: Event |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ Vue.use(Card);
|
|||||||
|
|
||||||
| 事件名 | 说明 | 回调参数 |
|
| 事件名 | 说明 | 回调参数 |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| click | 点击时触发 | - |
|
| click | 点击时触发 | event: Event |
|
||||||
| click-thumb | 点击自定义图片时触发 | - |
|
| click-thumb | 点击自定义图片时触发 | event: Event |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
@ -53,9 +53,9 @@ function Card(
|
|||||||
const showOriginPrice = slots['origin-price'] || isDef(props.originPrice);
|
const showOriginPrice = slots['origin-price'] || isDef(props.originPrice);
|
||||||
const showBottom = showNum || showPrice || showOriginPrice;
|
const showBottom = showNum || showPrice || showOriginPrice;
|
||||||
|
|
||||||
const onThumbClick = () => {
|
function onThumbClick(event: MouseEvent) {
|
||||||
emit(ctx, 'click-thumb');
|
emit(ctx, 'click-thumb', event);
|
||||||
};
|
}
|
||||||
|
|
||||||
function ThumbTag() {
|
function ThumbTag() {
|
||||||
if (slots.tag || props.tag) {
|
if (slots.tag || props.tag) {
|
||||||
|
@ -1,6 +1,47 @@
|
|||||||
import Card from '..';
|
import Card from '..';
|
||||||
import { mount } from '../../../test/utils';
|
import { mount } from '../../../test/utils';
|
||||||
|
|
||||||
|
test('click event', () => {
|
||||||
|
const onClick = jest.fn();
|
||||||
|
const wrapper = mount(Card, {
|
||||||
|
context: {
|
||||||
|
on: {
|
||||||
|
click: onClick
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.trigger('click');
|
||||||
|
|
||||||
|
expect(onClick).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
isTrusted: expect.any(Boolean)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('click-thumb event', () => {
|
||||||
|
const onClickThumb = jest.fn();
|
||||||
|
const wrapper = mount(Card, {
|
||||||
|
propsData: {
|
||||||
|
thumb: 'xx'
|
||||||
|
},
|
||||||
|
context: {
|
||||||
|
on: {
|
||||||
|
'click-thumb': onClickThumb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-card__thumb').trigger('click');
|
||||||
|
|
||||||
|
expect(onClickThumb).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
isTrusted: expect.any(Boolean)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('render price & num slot', () => {
|
test('render price & num slot', () => {
|
||||||
const wrapper = mount(Card, {
|
const wrapper = mount(Card, {
|
||||||
scopedSlots: {
|
scopedSlots: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user