[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
5 changed files with 29 additions and 2 deletions
+6 -2
View File
@@ -24,6 +24,7 @@ export type AddressItemProps = {
export type AddressItemEvents = { export type AddressItemEvents = {
onEdit(): void; onEdit(): void;
onClick(): void;
onSelect(): void; onSelect(): void;
}; };
@@ -37,10 +38,12 @@ function AddressItem(
) { ) {
const { disabled, switchable } = props; const { disabled, switchable } = props;
function onSelect() { function onClick() {
if (switchable) { if (switchable) {
emit(ctx, 'select'); emit(ctx, 'select');
} }
emit(ctx, 'click');
} }
const renderRightIcon = () => ( const renderRightIcon = () => (
@@ -50,6 +53,7 @@ function AddressItem(
onClick={(event: Event) => { onClick={(event: Event) => {
event.stopPropagation(); event.stopPropagation();
emit(ctx, 'edit'); emit(ctx, 'edit');
emit(ctx, 'click');
}} }}
/> />
); );
@@ -79,7 +83,7 @@ function AddressItem(
default: renderContent, default: renderContent,
'right-icon': renderRightIcon 'right-icon': renderRightIcon
}} }}
onClick={onSelect} onClick={onClick}
{...inherit(ctx)} {...inherit(ctx)}
/> />
); );
+1
View File
@@ -85,6 +85,7 @@ export default {
| select | Triggered when select address | item: address objectindex | | select | Triggered when select address | item: address objectindex |
| edit-disabled | Triggered when edit disabled address | item: address objectindex | | edit-disabled | Triggered when edit disabled address | item: address objectindex |
| select-disabled | Triggered when select 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 ### Data Structure of Address
+1
View File
@@ -86,6 +86,7 @@ export default {
| select | 切换选中的地址时触发 | item: 地址对象,index: 索引 | | select | 切换选中的地址时触发 | item: 地址对象,index: 索引 |
| edit-disabled | 编辑不可配送的地址时触发 | item: 地址对象,index: 索引 | | edit-disabled | 编辑不可配送的地址时触发 | item: 地址对象,index: 索引 |
| select-disabled | 选中不可配送的地址时触发 | item: 地址对象,index: 索引 | | select-disabled | 选中不可配送的地址时触发 | item: 地址对象,index: 索引 |
| click-item | 点击任意地址时触发 | item: 地址对象,index: 索引 |
### Address 数据结构 ### Address 数据结构
+3
View File
@@ -50,6 +50,9 @@ function AddressList(
onEdit={() => { onEdit={() => {
emit(ctx, disabled ? 'edit-disabled' : 'edit', item, index); emit(ctx, disabled ? 'edit-disabled' : 'edit', item, index);
}} }}
onClick={() => {
emit(ctx, 'click-item', item, index);
}}
/> />
)); ));
} }
+18
View File
@@ -44,3 +44,21 @@ test('select event', () => {
expect(onSelect).toHaveBeenCalledTimes(1); 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);
});