diff --git a/src/swipe-cell/README.md b/src/swipe-cell/README.md index 2494f1df2..52096e0df 100644 --- a/src/swipe-cell/README.md +++ b/src/swipe-cell/README.md @@ -93,6 +93,7 @@ export default { | Event | Description | Arguments | |------|------|------| | click | Triggered when clicked | Click positon (`left` `right` `cell` `outside`) | +| open | Triggered when opened | { position: 'left' \| 'right' , name: string } | ### onClose Params diff --git a/src/swipe-cell/README.zh-CN.md b/src/swipe-cell/README.zh-CN.md index 22739961f..16345cf60 100644 --- a/src/swipe-cell/README.zh-CN.md +++ b/src/swipe-cell/README.zh-CN.md @@ -98,6 +98,7 @@ export default { | 事件名 | 说明 | 回调参数 | |------|------|------| | click | 点击时触发 | 关闭时的点击位置 (`left` `right` `cell` `outside`) | +| open | 打开时触发 | { position: 'left' \| 'right' , name: string } | ### onClose 参数 diff --git a/src/swipe-cell/index.js b/src/swipe-cell/index.js index f39d75625..18640fcbf 100644 --- a/src/swipe-cell/index.js +++ b/src/swipe-cell/index.js @@ -59,6 +59,11 @@ export default createComponent({ const offset = position === 'left' ? this.computedLeftWidth : -this.computedRightWidth; this.swipeMove(offset); this.resetSwipeStatus(); + + this.$emit('open', { + position, + detail: this.name + }); }, close() { diff --git a/src/swipe-cell/test/index.spec.js b/src/swipe-cell/test/index.spec.js index 4ef68ad0e..c95c4dd65 100644 --- a/src/swipe-cell/test/index.spec.js +++ b/src/swipe-cell/test/index.spec.js @@ -1,5 +1,10 @@ import SwipeCell from '..'; -import { mount, triggerDrag, later, mockGetBoundingClientRect } from '../../../test/utils'; +import { + mount, + triggerDrag, + later, + mockGetBoundingClientRect +} from '../../../test/utils'; const THRESHOLD = 0.15; const defaultProps = { @@ -92,7 +97,7 @@ it('name prop', done => { it('should reset after drag', () => { const wrapper = mount(SwipeCell, defaultProps); - triggerDrag(wrapper, (defaultProps.leftWidth * THRESHOLD - 1), 0); + triggerDrag(wrapper, defaultProps.leftWidth * THRESHOLD - 1, 0); expect(wrapper.vm.offset).toEqual(0); }); @@ -100,7 +105,7 @@ it('disabled prop', () => { const wrapper = mount(SwipeCell, { propsData: { ...defaultProps.propsData, - disabled: true, + disabled: true } }); @@ -141,3 +146,23 @@ it('render one side', async () => { restoreMock(); }); + +it('trigger open event when open left side', () => { + const wrapper = mount(SwipeCell, defaultProps); + + triggerDrag(wrapper, 50, 0); + expect(wrapper.emitted('open')[0][0]).toEqual({ + detail: '', + position: 'left' + }); +}); + +it('trigger open event when open right side', () => { + const wrapper = mount(SwipeCell, defaultProps); + + triggerDrag(wrapper, -50, 0); + expect(wrapper.emitted('open')[0][0]).toEqual({ + detail: '', + position: 'right' + }); +});