Skip to content

Commit

Permalink
feat(AddressList): add event param for click-item (youzan#12748)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored and bluesky335 committed Apr 1, 2024
1 parent c04f2b7 commit 4484665
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/vant/src/address-list/AddressList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default defineComponent({
const onEdit = () =>
emit(disabled ? 'editDisabled' : 'edit', item, index);

const onClick = () => emit('clickItem', item, index);
const onClick = (event: MouseEvent) =>
emit('clickItem', item, index, { event });

const onSelect = () => {
emit(disabled ? 'selectDisabled' : 'select', item, index);
Expand Down
6 changes: 3 additions & 3 deletions packages/vant/src/address-list/AddressListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export default defineComponent({
emits: ['edit', 'click', 'select'],

setup(props, { slots, emit }) {
const onClick = () => {
const onClick = (event: MouseEvent) => {
if (props.switchable) {
emit('select');
}
emit('click');
emit('click', event);
};

const renderRightIcon = () => (
Expand All @@ -53,7 +53,7 @@ export default defineComponent({
onClick={(event) => {
event.stopPropagation();
emit('edit');
emit('click');
emit('click', event);
}}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/vant/src/address-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
| select | Emitted when an address is selected | _item: Address, index: number_ |
| edit-disabled | Emitted when the edit icon of disabled address is clicked | _item: Address, index: number_ |
| select-disabled | Emitted when a disabled address is selected | _item: Address, index: number_ |
| click-item | Emitted when an address item is clicked | _item: Address, index: number_ |
| click-item | Emitted when an address item is clicked | _item: Address, index: number, { event }_ |

### Data Structure of Address

Expand Down
2 changes: 1 addition & 1 deletion packages/vant/src/address-list/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
| select | 切换选中的地址时触发 | _item: AddressListAddress, index: number_ |
| edit-disabled | 编辑不可配送的地址时触发 | _item: AddressListAddress, index: number_ |
| select-disabled | 选中不可配送的地址时触发 | _item: AddressListAddress, index: number_ |
| click-item | 点击任意地址时触发 | _item: AddressListAddress, index: number_ |
| click-item | 点击任意地址时触发 | _item: AddressListAddress, index: number, { event }_ |

### AddressListAddress 数据结构

Expand Down
2 changes: 1 addition & 1 deletion packages/vant/src/address-list/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('should emit clickItem event when item is clicked', () => {

wrapper.find('.van-address-item').trigger('click');

expect(wrapper.emitted('clickItem')![0]).toEqual([list[0], 0]);
expect(wrapper.emitted('clickItem')![0].slice(0, 2)).toEqual([list[0], 0]);
});

test('should render tag slot correctly', () => {
Expand Down

0 comments on commit 4484665

Please sign in to comment.