Skip to content

Commit 9d21b53

Browse files
authored
feat(SwipeCell): add open event (youzan#4986)
1 parent 2c6b540 commit 9d21b53

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/swipe-cell/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default {
9393
| Event | Description | Arguments |
9494
|------|------|------|
9595
| click | Triggered when clicked | Click positon (`left` `right` `cell` `outside`) |
96+
| open | Triggered when opened | { position: 'left' \| 'right' , name: string } |
9697

9798
### onClose Params
9899

src/swipe-cell/README.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default {
9898
| 事件名 | 说明 | 回调参数 |
9999
|------|------|------|
100100
| click | 点击时触发 | 关闭时的点击位置 (`left` `right` `cell` `outside`) |
101+
| open | 打开时触发 | { position: 'left' \| 'right' , name: string } |
101102

102103
### onClose 参数
103104

src/swipe-cell/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export default createComponent({
5959
const offset = position === 'left' ? this.computedLeftWidth : -this.computedRightWidth;
6060
this.swipeMove(offset);
6161
this.resetSwipeStatus();
62+
63+
this.$emit('open', {
64+
position,
65+
detail: this.name
66+
});
6267
},
6368

6469
close() {

src/swipe-cell/test/index.spec.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import SwipeCell from '..';
2-
import { mount, triggerDrag, later, mockGetBoundingClientRect } from '../../../test/utils';
2+
import {
3+
mount,
4+
triggerDrag,
5+
later,
6+
mockGetBoundingClientRect
7+
} from '../../../test/utils';
38

49
const THRESHOLD = 0.15;
510
const defaultProps = {
@@ -92,15 +97,15 @@ it('name prop', done => {
9297
it('should reset after drag', () => {
9398
const wrapper = mount(SwipeCell, defaultProps);
9499

95-
triggerDrag(wrapper, (defaultProps.leftWidth * THRESHOLD - 1), 0);
100+
triggerDrag(wrapper, defaultProps.leftWidth * THRESHOLD - 1, 0);
96101
expect(wrapper.vm.offset).toEqual(0);
97102
});
98103

99104
it('disabled prop', () => {
100105
const wrapper = mount(SwipeCell, {
101106
propsData: {
102107
...defaultProps.propsData,
103-
disabled: true,
108+
disabled: true
104109
}
105110
});
106111

@@ -141,3 +146,23 @@ it('render one side', async () => {
141146

142147
restoreMock();
143148
});
149+
150+
it('trigger open event when open left side', () => {
151+
const wrapper = mount(SwipeCell, defaultProps);
152+
153+
triggerDrag(wrapper, 50, 0);
154+
expect(wrapper.emitted('open')[0][0]).toEqual({
155+
detail: '',
156+
position: 'left'
157+
});
158+
});
159+
160+
it('trigger open event when open right side', () => {
161+
const wrapper = mount(SwipeCell, defaultProps);
162+
163+
triggerDrag(wrapper, -50, 0);
164+
expect(wrapper.emitted('open')[0][0]).toEqual({
165+
detail: '',
166+
position: 'right'
167+
});
168+
});

0 commit comments

Comments
 (0)