Skip to content

Commit fc4869c

Browse files
authored
Merge pull request #2911 from adumesny/master
web component .no-drag test
2 parents f988e83 + 71dff47 commit fc4869c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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>Custom element test</title>
8+
<link rel="stylesheet" href="../../../demo/demo.css" />
9+
<script src="../../../dist/gridstack-all.js"></script>
10+
</head>
11+
<body>
12+
<p> cancel:".no-drag" does not work when placed within a web component (case 2)</p>
13+
<div class="grid-stack"></div>
14+
<script type="text/javascript">
15+
// NOTE: REAL apps would sanitize-html or DOMPurify before blinding setting innerHTML. see #2736
16+
GridStack.renderCB = function (el, w) {
17+
el.innerHTML = w.content;
18+
};
19+
20+
class CustomElement extends HTMLElement {
21+
constructor(name) {
22+
super();
23+
this.subject = name || "World";
24+
// create a Shadow DOM
25+
this.root = this.attachShadow({ mode: "open" });
26+
}
27+
// run some code when the component is ready
28+
connectedCallback() {
29+
this.root.innerHTML = this.getTemplate();
30+
}
31+
// create templates that interpolate variables and HTML!
32+
getTemplate() {
33+
return `<div>web component case:</div><button onclick=\"alert('clicked!')\">Press me</button><div>text area</div><div><textarea></textarea></div><div>Input Field</div><input type="text"><div contenteditable=\"true\">Editable Div</div><div class=\"no-drag\">SHOULD be no drag</div>`;
34+
}
35+
}
36+
customElements.define("custom-element", CustomElement);
37+
38+
var children = [
39+
{ content: "0" },
40+
{ w: 2, h: 3, content: `<button onclick=\"alert('clicked!')\">Press me</button><div>text area</div><div><textarea></textarea></div><div>Input Field</div><input type="text"><div contenteditable=\"true\">Editable Div</div><div class=\"no-drag\">no drag</div>` },
41+
{ w: 2, h: 3, content: `<custom-element></custom-element>` },
42+
];
43+
44+
var options = {
45+
// put in gridstack options here
46+
cellHeight: 80,
47+
children,
48+
draggable: {
49+
cancel: ".no-drag",
50+
}, // example of additional custom elements to skip drag on
51+
};
52+
var grid = GridStack.init(options);
53+
</script>
54+
</body>
55+
</html>

0 commit comments

Comments
 (0)