feat(Swipe): add index when trigger onDragStart or onDragEnd (#11632)

* perf(Swipe): add index when trigger onDragStart or onDragEnd

* perf(Swipe): change the arguments of the onDragStart and onDragEnd events to the Object

---------

Co-authored-by: ZZQChongYa <zhengziqiang@star-net.cn>
This commit is contained in:
SaberA1ter 2023-03-04 15:19:31 +08:00 committed by GitHub
parent c63fee0d13
commit 2d72821de0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View File

@ -161,8 +161,8 @@ export default {
| Event | Description | Arguments |
| --- | --- | --- |
| change | Emitted when current swipe changed | _index: number_ |
| drag-start `v4.0.9` | Emitted when user starts dragging the swipe | - |
| drag-end `v4.0.9` | Emitted when user ends dragging the swipe | - |
| drag-start `v4.0.9` | Emitted when user starts dragging the swipe | _{ index: number }_ |
| drag-end `v4.0.9` | Emitted when user ends dragging the swipe | _{ index: number }_ |
### SwipeItem Events

View File

@ -166,11 +166,11 @@ export default {
### Swipe Events
| 事件名 | 说明 | 回调参数 |
| ------------------- | ---------------------------- | --------------- |
| change | 每一页轮播结束后触发 | _index: number_ |
| drag-start `v4.0.9` | 当用户开始拖动轮播组件时触发 | - |
| drag-end `v4.0.9` | 当用户结束拖动轮播组件时触发 | - |
| 事件名 | 说明 | 回调参数 |
| ------------------- | ---------------------------- | ------------------- |
| change | 每一页轮播结束后触发 | _index: number_ |
| drag-start `v4.0.9` | 当用户开始拖动轮播组件时触发 | _{ index: number }_ |
| drag-end `v4.0.9` | 当用户结束拖动轮播组件时触发 | _{ index: number }_ |
### SwipeItem Events

View File

@ -333,7 +333,7 @@ export default defineComponent({
move({ offset: delta.value });
if (!dragging) {
emit('dragStart');
emit('dragStart', { index: activeIndicator.value });
dragging = true;
}
}
@ -377,7 +377,7 @@ export default defineComponent({
dragging = false;
state.swiping = false;
emit('dragEnd');
emit('dragEnd', { index: activeIndicator.value });
autoplay();
};

View File

@ -350,9 +350,13 @@ test('should emit drag-start and drag-end events correctly', async () => {
await triggerDrag(track, 100, 0);
expect(dragStart).toHaveBeenCalledTimes(1);
expect(dragStart).toHaveBeenCalledWith({ index: 0 });
expect(dragEnd).toHaveBeenCalledTimes(1);
expect(dragEnd).toHaveBeenCalledWith({ index: 1 });
await triggerDrag(track, 100, 0);
expect(dragStart).toHaveBeenCalledTimes(2);
expect(dragStart).toHaveBeenCalledWith({ index: 1 });
expect(dragEnd).toHaveBeenCalledTimes(2);
expect(dragEnd).toHaveBeenCalledWith({ index: 0 });
});