Skip to content

Commit 288f34a

Browse files
committed
h5: drag fix
* fix #1511 * you can now click any grid item content and drag away * added sample test case
1 parent 8d13204 commit 288f34a

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Change log
5252

5353
- fix [1330](https://github.com/gridstack/gridstack.js/issues/1330) `maxW` does not work as intended with resizable handle `"w"`
5454
- fix [1472](https://github.com/gridstack/gridstack.js/issues/1472) support all options for new dragged in widgets (read all `gs-xyz` attributes)
55+
- fix [1511](https://github.com/gridstack/gridstack.js/issues/1511) dragging any grid item content works
5556

5657
## 3.1.0 (2020-12-4)
5758

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Float grid demo</title>
8+
<link rel="stylesheet" href="../../../demo/demo.css"/>
9+
<script src="../../../dist/gridstack-h5.js"></script>
10+
<style>
11+
.x {
12+
width:100%;
13+
height:100%;
14+
}
15+
</style>
16+
17+
</head>
18+
<body>
19+
<div class="container-fluid">
20+
<h1>Float grid demo</h1>
21+
<br><br>
22+
<div class="grid-stack"></div>
23+
</div>
24+
<script src="../../../demo/events.js"></script>
25+
<script type="text/javascript">
26+
let grid = GridStack.init({float: true, cellHeight: 70});
27+
addEvents(grid);
28+
var items = [
29+
{x: 0, y: 0, w: 2, h: 2, content: '<table class="x"><tr><td><span>table should work</span></td></tr></table>'},
30+
{x: 2, y: 0, w: 2, h: 2, content: '<div class="x"><span>using a span</span></div>'},
31+
{x: 4, y: 0, w: 2, h: 2, content: '<div class="x">using a div</div>'},
32+
{x: 6, y: 0, w: 2, h: 2, content: 'works anywhere'},
33+
];
34+
35+
grid.load(items);
36+
</script>
37+
</body>
38+
</html>

src/h5/dd-draggable.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,18 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
121121
return this;
122122
}
123123

124-
/** @internal */
124+
/** @internal call when mouse goes down before a dragstart happens */
125125
private _mouseDown(event: MouseEvent): void {
126-
this.mouseDownElement = event.target as HTMLElement;
126+
// make sure we are clicking on a drag handle or child of it...
127+
let className = this.option.handle.substring(1);
128+
let el = event.target as HTMLElement;
129+
while (el && !el.classList.contains(className)) { el = el.parentElement; }
130+
this.mouseDownElement = el;
127131
}
128132

129133
/** @internal */
130134
private _dragStart(event: DragEvent): void {
131-
if (this.option.handle && !(
132-
this.mouseDownElement
133-
&& this.mouseDownElement.matches(
134-
`${this.option.handle}, ${this.option.handle} > *`
135-
)
136-
)) {
137-
event.preventDefault();
138-
return;
139-
}
135+
if (!this.mouseDownElement) { event.preventDefault(); return; }
140136
DDManager.dragElement = this;
141137
this.helper = this._createHelper(event);
142138
this._setupHelperContainmentStyle();

0 commit comments

Comments
 (0)