Skip to content

Commit b9f8b3a

Browse files
committed
test(reorder-group): update data test to reorder the DOM
1 parent 7948ef4 commit b9f8b3a

File tree

1 file changed

+34
-17
lines changed
  • core/src/components/reorder-group/test/data

1 file changed

+34
-17
lines changed

core/src/components/reorder-group/test/data/index.html

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
1515
</head>
1616

17-
<body onLoad="render()">
17+
<body>
1818
<ion-app>
1919
<ion-header>
2020
<ion-toolbar>
@@ -24,7 +24,7 @@
2424

2525
<ion-content id="content">
2626
<ion-list>
27-
<ion-reorder-group id="reorderGroup" disabled="false">
27+
<ion-reorder-group disabled="false">
2828
<!-- items will be inserted here -->
2929
</ion-reorder-group>
3030
</ion-list>
@@ -36,27 +36,44 @@
3636
for (var i = 0; i < 30; i++) {
3737
items.push(i + 1);
3838
}
39-
const reorderGroup = document.getElementById('reorderGroup');
40-
41-
function render() {
42-
let html = '';
43-
for (let item of items) {
44-
html += `
45-
<ion-item>
46-
<ion-label>${item}</ion-label>
47-
<ion-reorder slot="end"></ion-reorder>
48-
</ion-item>`;
49-
}
50-
reorderGroup.innerHTML = html;
51-
}
39+
const reorderGroup = document.querySelector('ion-reorder-group');
40+
reorderItems(items);
5241

5342
reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
54-
console.log('Dragged from index', detail.from, 'to', detail.to);
55-
43+
// Before complete is called with the items they will remain in the
44+
// order before the drag
5645
console.log('Before complete', items);
46+
47+
// Finish the reorder and position the item in the DOM based on
48+
// where the gesture ended. Update the items variable to the
49+
// new order of items
5750
items = detail.complete(items);
51+
52+
// Reorder the items in the DOM
53+
reorderItems(items);
54+
55+
// After complete is called the items will be in the new order
5856
console.log('After complete', items);
5957
});
58+
59+
function reorderItems(items) {
60+
reorderGroup.replaceChildren();
61+
62+
let reordered = '';
63+
64+
for (let i = 0; i < items.length; i++) {
65+
reordered += `
66+
<ion-item>
67+
<ion-label>
68+
Item ${items[i]}
69+
</ion-label>
70+
<ion-reorder slot="end"></ion-reorder>
71+
</ion-item>
72+
`;
73+
}
74+
75+
reorderGroup.innerHTML = reordered;
76+
}
6077
</script>
6178
</body>
6279
</html>

0 commit comments

Comments
 (0)