Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cb7d2f1
chore: use dev build
brandyscarney Jun 12, 2025
4a6ee9b
docs(reorder): update onIonItemReorder -> onIonReorderEnd
brandyscarney Jun 12, 2025
e11dbd5
style: lint
brandyscarney Jun 12, 2025
10e9ab0
fix(api): update the events table to include the deprecated description
brandyscarney Jun 12, 2025
6faa3bf
docs(reorder-group): add new interfaces and deprecate old ones
brandyscarney Jun 12, 2025
f99931c
chore: latest dev build
brandyscarney Jun 12, 2025
d9c35ec
fix(api): bold deprecated and move to its own line
brandyscarney Jun 12, 2025
5166f6e
docs(reorder): ionItemReorder -> ionReorderEnd
brandyscarney Jun 12, 2025
1b3b3ca
docs(reorder): set width of existing demos to 300px
brandyscarney Jun 13, 2025
2f597e8
docs(reorder): CustomEvent<ItemReorderEventDetail> -> ReorderEndCusto…
brandyscarney Jun 13, 2025
01f0b2e
docs(reorder): rename handleReorder functions to handleReorderEnd
brandyscarney Jun 13, 2025
5f901b4
style: lint
brandyscarney Jun 13, 2025
ce444b7
docs(reorder): add reorder-start-end playground
brandyscarney Jun 13, 2025
fa1e85b
style: comments and logs
brandyscarney Jun 13, 2025
e46a45e
docs(reorder): update reorder start end to set items data
brandyscarney Jun 13, 2025
15db739
docs(reorder): add reorder move playground
brandyscarney Jun 13, 2025
dc1311f
docs(reorder): update event handling descriptions and add logs
brandyscarney Jun 13, 2025
c0a6928
docs(reorder): rename playgrounds
brandyscarney Jun 13, 2025
6fe29a3
docs(reorder): copy editing
brandyscarney Jun 23, 2025
80b3a91
docs(reorder): copy editing
brandyscarney Jun 23, 2025
7ab2e2c
chore: revert dev build
brandyscarney Jun 23, 2025
e3ec9a6
style: lint
brandyscarney Jun 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(reorder): add reorder move playground
  • Loading branch information
brandyscarney committed Jun 23, 2025
commit 15db7397d586274f9c89f4cafe6259d113f18848
13 changes: 13 additions & 0 deletions docs/api/reorder.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ import UpdatingData from '@site/static/usage/v8/reorder/updating-data/index.md';

<UpdatingData />

## Event Handling
Comment thread
brandyscarney marked this conversation as resolved.

### Using `ionReorderStart` and `ionReorderEnd`

import ReorderStartEnd from '@site/static/usage/v8/reorder/reorder-start-end/index.md';

<ReorderStartEnd />

### Using `ionReorderMove`

import ReorderMove from '@site/static/usage/v8/reorder/reorder-move/index.md';

<ReorderMove />

## Usage with Virtual Scroll

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```html
<ion-list lines="full">
<!-- The reorder gesture is disabled by default, enable it to drag and drop items -->
<!-- Casting $event to $any is a temporary fix for this bug https://github.com/ionic-team/ionic-framework/issues/24245 -->
<ion-reorder-group
[disabled]="false"
(ionReorderMove)="handleReorderMove($any($event))"
(ionReorderEnd)="handleReorderEnd($any($event))"
>
@for (item of items; track item; let i = $index) {
<ion-item [id]="'item-' + (i + 1)">
<b slot="start">{{ i + 1 }}</b>
<ion-label>{{ item }}</ion-label>
<ion-reorder slot="end"></ion-reorder>
</ion-item>
}
</ion-reorder-group>
</ion-list>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
```ts
import { Component } from '@angular/core';
import {
IonItem,
IonLabel,
IonList,
IonReorder,
IonReorderGroup,
ReorderEndCustomEvent,
ReorderMoveCustomEvent,
} from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonItem, IonLabel, IonList, IonReorder, IonReorderGroup],
})
export class ExampleComponent {
items = ['Buy groceries', 'Call the bank', 'Finish project report', 'Book flight tickets', 'Read a book'];

handleReorderMove(event: ReorderMoveCustomEvent) {
const from = event.detail.from;
const to = event.detail.to;

// Get all items and sort by their current id (item-1, item-2, ...)
const itemElements = Array.from(document.querySelectorAll('ion-item')).sort((a, b) => {
const aNum = parseInt(a.id.replace('item-', ''), 10);
const bNum = parseInt(b.id.replace('item-', ''), 10);
return aNum - bNum;
});

// Dragging down: shift up items between from+1 and to, set dragged to to+1
if (from < to) {
for (let i = from; i <= to; i++) {
const item = itemElements[i];
const itemNum = item.querySelector('b');
if (itemNum) {
if (i === from) {
// Dragged item
itemNum.textContent = String(to + 1);
item.id = `item-${to + 1}`;
} else {
// Items shift up
itemNum.textContent = String(i);
item.id = `item-${i}`;
}
}
}
// Dragging up: shift down items between to and from-1, set dragged to to+1
} else if (from > to) {
for (let i = to; i <= from; i++) {
const item = itemElements[i];
const itemNum = item.querySelector('b');
if (itemNum) {
if (i === from) {
// Dragged item
itemNum.textContent = String(to + 1);
item.id = `item-${to + 1}`;
} else {
// Items shift down
itemNum.textContent = String(i + 2);
item.id = `item-${i + 2}`;
}
}
}
}
}

handleReorderEnd(event: ReorderEndCustomEvent) {
// Finish the reorder and update the items data
this.items = event.detail.complete(this.items);
}
}
```
118 changes: 118 additions & 0 deletions static/usage/v8/reorder/reorder-move/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Reorder</title>
<link rel="stylesheet" href="../../common.css" />
<script src="../../common.js"></script>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@ionic/core@8.6.2-dev.11749759855.198287b7/dist/ionic/ionic.esm.js"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@ionic/core@8.6.2-dev.11749759855.198287b7/css/ionic.bundle.css"
/>

<style>
ion-list {
width: 300px;
}
</style>
</head>

<body>
<ion-app>
<ion-content>
<div class="container">
<ion-list lines="full">
<!-- The reorder gesture is disabled by default, enable it to drag and drop items -->
<ion-reorder-group disabled="false"></ion-reorder-group>
</ion-list>
</div>
</ion-content>
</ion-app>

<script>
let items = ['Buy groceries', 'Call the bank', 'Finish project report', 'Book flight tickets', 'Read a book'];
const reorderGroup = document.querySelector('ion-reorder-group');

document.addEventListener('DOMContentLoaded', () => {
reorderItems(items);
});

reorderGroup.addEventListener('ionReorderMove', ({ detail }) => {
const from = detail.from;
const to = detail.to;

// Get all items and sort by their current id (item-1, item-2, ...)
const itemElements = Array.from(reorderGroup.querySelectorAll('ion-item')).sort((a, b) => {
const aNum = parseInt(a.id.replace('item-', ''), 10);
const bNum = parseInt(b.id.replace('item-', ''), 10);
return aNum - bNum;
});

// Dragging down: shift up items between from+1 and to, set dragged to to+1
if (from < to) {
for (let i = from; i <= to; i++) {
const item = itemElements[i];
const itemNum = item.querySelector('b');
if (i === from) {
// Dragged item
itemNum.textContent = to + 1;
item.id = `item-${to + 1}`;
} else {
// Items shift up
itemNum.textContent = i;
item.id = `item-${i}`;
}
}
// Dragging up: shift down items between to and from-1, set dragged to to+1
} else if (from > to) {
for (let i = to; i <= from; i++) {
const item = itemElements[i];
const itemNum = item.querySelector('b');
if (i === from) {
// Dragged item
itemNum.textContent = to + 1;
item.id = `item-${to + 1}`;
} else {
// Items shift down
itemNum.textContent = i + 2;
item.id = `item-${i + 2}`;
}
}
}
});

reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
// Finish the reorder and update the items data
items = detail.complete(items);

// Re-render the DOM to match the new order
reorderItems(items);
});

function reorderItems(items) {
reorderGroup.replaceChildren();

let reordered = '';

for (let i = 0; i < items.length; i++) {
reordered += `
<ion-item id="item-${i + 1}">
<b slot="start">${i + 1}</b>
<ion-label>
${items[i]}
</ion-label>
<ion-reorder slot="end"></ion-reorder>
</ion-item>
`;
}

reorderGroup.innerHTML = reordered;
}
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions static/usage/v8/reorder/reorder-move/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Playground from '@site/src/components/global/Playground';

import javascript from './javascript.md';
import react from './react.md';
import vue from './vue.md';

import angular_example_component_ts from './angular/example_component_ts.md';
import angular_example_component_html from './angular/example_component_html.md';

<Playground
version="8"
code={{
javascript,
react,
vue,
angular: {
files: {
'src/app/example.component.ts': angular_example_component_ts,
'src/app/example.component.html': angular_example_component_html,
},
},
}}
src="usage/v8/reorder/reorder-move/demo.html"
size="300px"
/>
85 changes: 85 additions & 0 deletions static/usage/v8/reorder/reorder-move/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
```html
<ion-list lines="full">
<!-- The reorder gesture is disabled by default, enable it to drag and drop items -->
<ion-reorder-group disabled="false"></ion-reorder-group>
</ion-list>

<script>
let items = ['Buy groceries', 'Call the bank', 'Finish project report', 'Book flight tickets', 'Read a book'];
const reorderGroup = document.querySelector('ion-reorder-group');

reorderItems(items);

reorderGroup.addEventListener('ionReorderMove', ({ detail }) => {
const from = detail.from;
const to = detail.to;

// Get all items and sort by their current id (item-1, item-2, ...)
const itemElements = Array.from(reorderGroup.querySelectorAll('ion-item')).sort((a, b) => {
const aNum = parseInt(a.id.replace('item-', ''), 10);
const bNum = parseInt(b.id.replace('item-', ''), 10);
return aNum - bNum;
});

// Dragging down: shift up items between from+1 and to, set dragged to to+1
if (from < to) {
for (let i = from; i <= to; i++) {
const item = itemElements[i];
const itemNum = item.querySelector('b');
if (i === from) {
// Dragged item
itemNum.textContent = to + 1;
item.id = `item-${to + 1}`;
} else {
// Items shift up
itemNum.textContent = i;
item.id = `item-${i}`;
}
}
// Dragging up: shift down items between to and from-1, set dragged to to+1
} else if (from > to) {
for (let i = to; i <= from; i++) {
const item = itemElements[i];
const itemNum = item.querySelector('b');
if (i === from) {
// Dragged item
itemNum.textContent = to + 1;
item.id = `item-${to + 1}`;
} else {
// Items shift down
itemNum.textContent = i + 2;
item.id = `item-${i + 2}`;
}
}
}
});

reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
// Finish the reorder and update the items data
items = detail.complete(items);

// Re-render the DOM to match the new order
reorderItems(items);
});

function reorderItems(items) {
reorderGroup.replaceChildren();

let reordered = '';

for (let i = 0; i < items.length; i++) {
reordered += `
<ion-item id="item-${i + 1}">
<b slot="start">${i + 1}</b>
<ion-label>
${items[i]}
</ion-label>
<ion-reorder slot="end"></ion-reorder>
</ion-item>
`;
}

reorderGroup.innerHTML = reordered;
}
</script>
```
Loading