Skip to content

Commit a63bbf9

Browse files
committed
feat(Fab): add drag-start and drag-end events
1 parent 70ab1d4 commit a63bbf9

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

src/fab/__test__/__snapshots__/demo.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ exports[`Fab Fab draggable demo works fine 1`] = `
4141
]
4242
}}"
4343
bind:click="handleClick"
44-
bind:move="handleMove"
44+
bind:dragend="handleDragEnd"
45+
bind:dragstart="handleDragStart"
4546
/>
4647
</draggable>
4748
`;

src/fab/_example/draggable/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
Component({
22
methods: {
33
handleClick(e) {
4-
console.log(e);
4+
console.log('handleClick: ', e);
55
},
6-
handleMove(e) {
7-
console.log(e);
6+
7+
handleDragStart(e) {
8+
console.log('handleDragStart: ', e);
9+
},
10+
11+
handleDragEnd(e) {
12+
console.log('handleDragEnd: ', e);
813
},
914
},
1015
});

src/fab/_example/draggable/index.wxml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<t-fab
22
icon="gesture-press"
33
text="拖我"
4-
bind:click="handleClick"
5-
bind:move="handleMove"
64
aria-label="增加"
75
usingCustomNavbar
86
draggable
97
y-bounds="{{[0, 32]}}"
8+
bind:click="handleClick"
9+
bind:dragstart="handleDragStart"
10+
bind:dragend="handleDragEnd"
1011
></t-fab>

src/fab/fab.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export default class Fab extends SuperComponent {
5050
onTplButtonTap(e) {
5151
this.triggerEvent('click', e);
5252
},
53+
54+
onStart(e) {
55+
this.triggerEvent('dragstart', e.detail.e);
56+
},
57+
5358
onMove(e) {
5459
const { yBounds } = this.properties;
5560
const { distanceTop } = this.data;
@@ -64,6 +69,11 @@ export default class Fab extends SuperComponent {
6469
moveStyle: `right: ${right}px; bottom: ${bottom}px;`,
6570
});
6671
},
72+
73+
onEnd(e) {
74+
this.triggerEvent('dragend', e.detail.e);
75+
},
76+
6777
computedSize() {
6878
if (!this.properties.draggable) return;
6979
const insChild = this.selectComponent('#draggable');

src/fab/template/draggable.wxml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
id="draggable"
77
style="right: 16px; bottom: 32px; {{_._style([style, customStyle, moveStyle])}}"
88
direction="{{draggable === true ? 'all' : draggable}}"
9+
bind:start="onStart"
910
bind:move="onMove"
11+
bind:end="onEnd"
1012
>
1113
<template is="button" data="{{...buttonData}}" />
1214
</t-draggable>

0 commit comments

Comments
 (0)