feat(SwipeCell): add open event (#4986)

This commit is contained in:
neverland 2019-11-12 21:03:48 +08:00 committed by GitHub
parent 2c6b5408d3
commit 9d21b53731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 3 deletions

View File

@ -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

View File

@ -98,6 +98,7 @@ export default {
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| click | 点击时触发 | 关闭时的点击位置 (`left` `right` `cell` `outside`) |
| open | 打开时触发 | { position: 'left' \| 'right' , name: string } |
### onClose 参数

View File

@ -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() {

View File

@ -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'
});
});