mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(SwipeCell): add open event (#4986)
This commit is contained in:
parent
2c6b5408d3
commit
9d21b53731
@ -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
|
||||
|
||||
|
@ -98,6 +98,7 @@ export default {
|
||||
| 事件名 | 说明 | 回调参数 |
|
||||
|------|------|------|
|
||||
| click | 点击时触发 | 关闭时的点击位置 (`left` `right` `cell` `outside`) |
|
||||
| open | 打开时触发 | { position: 'left' \| 'right' , name: string } |
|
||||
|
||||
### onClose 参数
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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'
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user