mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] AddressList: add click-item event (#3942)
This commit is contained in:
parent
4d0d54dbf4
commit
42afafac2b
@ -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)}
|
||||
/>
|
||||
);
|
||||
|
@ -85,6 +85,7 @@ export default {
|
||||
| select | Triggered when select address | item: address object,index |
|
||||
| edit-disabled | Triggered when edit disabled address | item: address object,index |
|
||||
| select-disabled | Triggered when select disabled address | item: address object,index |
|
||||
| click-item | Triggered when click address item | item: address object,index |
|
||||
|
||||
### Data Structure of Address
|
||||
|
||||
|
@ -86,6 +86,7 @@ export default {
|
||||
| select | 切换选中的地址时触发 | item: 地址对象,index: 索引 |
|
||||
| edit-disabled | 编辑不可配送的地址时触发 | item: 地址对象,index: 索引 |
|
||||
| select-disabled | 选中不可配送的地址时触发 | item: 地址对象,index: 索引 |
|
||||
| click-item | 点击任意地址时触发 | item: 地址对象,index: 索引 |
|
||||
|
||||
### Address 数据结构
|
||||
|
||||
|
@ -50,6 +50,9 @@ function AddressList(
|
||||
onEdit={() => {
|
||||
emit(ctx, disabled ? 'edit-disabled' : 'edit', item, index);
|
||||
}}
|
||||
onClick={() => {
|
||||
emit(ctx, 'click-item', item, index);
|
||||
}}
|
||||
/>
|
||||
));
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user