[new feature] AddressList: add click-item event (#3942)

This commit is contained in:
neverland 2019-07-23 20:50:31 +08:00 committed by GitHub
parent 4d0d54dbf4
commit 42afafac2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 2 deletions

View File

@ -24,6 +24,7 @@ export type AddressItemProps = {
export type AddressItemEvents = {
onEdit(): void;
onClick(): void;
onSelect(): void;
};
@ -37,10 +38,12 @@ function AddressItem(
) {
const { disabled, switchable } = props;
function onSelect() {
function onClick() {
if (switchable) {
emit(ctx, 'select');
}
emit(ctx, 'click');
}
const renderRightIcon = () => (
@ -50,6 +53,7 @@ function AddressItem(
onClick={(event: Event) => {
event.stopPropagation();
emit(ctx, 'edit');
emit(ctx, 'click');
}}
/>
);
@ -79,7 +83,7 @@ function AddressItem(
default: renderContent,
'right-icon': renderRightIcon
}}
onClick={onSelect}
onClick={onClick}
{...inherit(ctx)}
/>
);

View File

@ -85,6 +85,7 @@ export default {
| select | Triggered when select address | item: address objectindex |
| edit-disabled | Triggered when edit disabled address | item: address objectindex |
| select-disabled | Triggered when select disabled address | item: address objectindex |
| click-item | Triggered when click address item | item: address objectindex |
### Data Structure of Address

View File

@ -86,6 +86,7 @@ export default {
| select | 切换选中的地址时触发 | item: 地址对象index: 索引 |
| edit-disabled | 编辑不可配送的地址时触发 | item: 地址对象index: 索引 |
| select-disabled | 选中不可配送的地址时触发 | item: 地址对象index: 索引 |
| click-item | 点击任意地址时触发 | item: 地址对象index: 索引 |
### Address 数据结构

View File

@ -50,6 +50,9 @@ function AddressList(
onEdit={() => {
emit(ctx, disabled ? 'edit-disabled' : 'edit', item, index);
}}
onClick={() => {
emit(ctx, 'click-item', item, index);
}}
/>
));
}

View File

@ -44,3 +44,21 @@ test('select event', () => {
expect(onSelect).toHaveBeenCalledTimes(1);
});
test('click-item event', () => {
const onClickItem = jest.fn();
const wrapper = mount(AddressList, {
propsData: {
list
},
context: {
on: {
'click-item': onClickItem
}
}
});
wrapper.find('.van-address-item').trigger('click');
expect(onClickItem).toHaveBeenCalledTimes(1);
});