Skip to content

Commit f634bb2

Browse files
authored
Backport 'Fix drag_and_drop on mobile without scrolling' to v0.30 (#94)
1 parent aea6f9e commit f634bb2

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

  • decidim-forms/app/packs/src/decidim/forms

decidim-forms/app/packs/src/decidim/forms/forms.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,31 @@ $(() => {
3535
}
3636
});
3737

38-
document.querySelectorAll(".js-sortable-check-box-collection").forEach((el) => new DragonDrop(el, {
39-
handle: false,
40-
item: ".js-collection-input"
41-
}));
38+
document.querySelectorAll(".js-sortable-check-box-collection").forEach((el) => {
39+
40+
/**
41+
* Due to a bug reported in https://github.com/decidim/decidim/issues/15191
42+
* we have to listen to the `drag` event and prevent the scrolling
43+
* and enabling it back again after it.
44+
*/
45+
46+
let preventScroll = function(event) {
47+
event.preventDefault();
48+
}
49+
50+
el.addEventListener("touchmove", (event) => {
51+
preventScroll(event);
52+
}, { passive: false });
53+
54+
el.addEventListener("touchend", () => {
55+
el.removeEventListener("touchmove", preventScroll)
56+
});
57+
58+
return new DragonDrop(el, {
59+
handle: false,
60+
item: ".js-collection-input"
61+
});
62+
});
4263

4364
$(".answer-questionnaire .question[data-conditioned='true']").each((idx, el) => {
4465
createDisplayConditions({

0 commit comments

Comments
 (0)