[bugfix] AddressList: not trigger select event when click radio icon (#3214)

This commit is contained in:
neverland 2019-04-26 09:25:57 +08:00 committed by GitHub
parent 5889968f29
commit 6fbdc4ffc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 7 deletions

View File

@ -36,6 +36,12 @@ function AddressItem(
) {
const { disabled, switchable } = props;
const onSelect = () => {
if (props.switchable) {
emit(ctx, 'select');
}
};
const renderRightIcon = () => (
<Icon
name="edit"
@ -54,13 +60,13 @@ function AddressItem(
<div class={bem('address')}>{data.address}</div>
];
return props.switchable ? <Radio name={data.id}>{Info}</Radio> : Info;
};
const onSelect = () => {
if (props.switchable) {
emit(ctx, 'select');
}
return props.switchable ? (
<Radio name={data.id} onClick={onSelect}>
{Info}
</Radio>
) : (
Info
);
};
return (

View File

@ -26,3 +26,21 @@ test('unswitchable', () => {
expect(wrapper).toMatchSnapshot();
});
test('select event', () => {
const onSelect = jest.fn();
const wrapper = mount(AddressList, {
propsData: {
list
},
context: {
on: {
select: onSelect
}
}
});
wrapper.find('.van-radio__icon').trigger('click');
expect(onSelect).toHaveBeenCalled();
});