[improvement] Card: add click event params (#3780)

This commit is contained in:
neverland 2019-07-08 17:02:12 +08:00 committed by GitHub
parent abc555dd72
commit 701446ece8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 7 deletions

View File

@ -80,8 +80,8 @@ Use slot to custom content.
| Event | Description | Arguments |
|------|------|------|
| click | Triggered when clicked | - |
| click-thumb | Triggered when thumb clicked | - |
| click | Triggered when clicked | event: Event |
| click-thumb | Triggered when thumb clicked | event: Event |
### Slots

View File

@ -82,8 +82,8 @@ Vue.use(Card);
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| click | 点击时触发 | - |
| click-thumb | 点击自定义图片时触发 | - |
| click | 点击时触发 | event: Event |
| click-thumb | 点击自定义图片时触发 | event: Event |
### Slots

View File

@ -53,9 +53,9 @@ function Card(
const showOriginPrice = slots['origin-price'] || isDef(props.originPrice);
const showBottom = showNum || showPrice || showOriginPrice;
const onThumbClick = () => {
emit(ctx, 'click-thumb');
};
function onThumbClick(event: MouseEvent) {
emit(ctx, 'click-thumb', event);
}
function ThumbTag() {
if (slots.tag || props.tag) {

View File

@ -1,6 +1,47 @@
import Card from '..';
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', () => {
const wrapper = mount(Card, {
scopedSlots: {