Skip to content

Commit e9cc2a9

Browse files
docs(reorder): add new ionReorderStart, ionReorderMove, ionReorderEnd event playgrounds (#4149)
Co-authored-by: Brandy Smith <[email protected]>
1 parent 68c4806 commit e9cc2a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1137
-117
lines changed

docs/api/reorder-group.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,71 @@ import Slots from '@ionic-internal/component-api/v8/reorder-group/slots.md';
1616
import EncapsulationPill from '@components/page/api/EncapsulationPill';
1717

1818

19-
The reorder group is a container for items using the [reorder](./reorder) component. When the user drags an item and drops it in a new position, the `ionItemReorder` event is dispatched. A handler for this event should be implemented that calls the `complete` method.
19+
The reorder group is a container for items using the [reorder](./reorder) component. When the user drags an item and drops it, the `ionReorderEnd` event is dispatched. A handler for this event should be implemented that calls the `complete` method.
2020

21-
The `detail` property of the `ionItemReorder` event includes all of the relevant information about the reorder operation, including the `from` and `to` indexes. In the context of reordering, an item moves `from` an index `to` a new index. For example usage of the reorder group, see the [reorder](./reorder) documentation.
21+
The `detail` property of the `ionReorderEnd` event includes all of the relevant information about the reorder operation, including the `from` and `to` indexes. In the context of reordering, an item moves `from` an index `to` an index. For example usage of the reorder group, see the [reorder](./reorder) documentation.
2222

2323

2424
## Interfaces
2525

26-
### ItemReorderEventDetail
26+
### ReorderMoveEventDetail
2727

2828
```typescript
29-
interface ItemReorderEventDetail {
29+
interface ReorderMoveEventDetail {
30+
from: number;
31+
to: number;
32+
}
33+
```
34+
35+
### ReorderEndEventDetail
36+
37+
```typescript
38+
interface ReorderEndEventDetail {
3039
from: number;
3140
to: number;
3241
complete: (data?: boolean | any[]) => any;
3342
}
3443
```
3544

36-
### ItemReorderCustomEvent
45+
### ReorderMoveCustomEvent
46+
47+
While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing with Ionic events emitted from this component.
48+
49+
```typescript
50+
interface ReorderMoveCustomEvent extends CustomEvent {
51+
detail: ReorderMoveEventDetail;
52+
target: HTMLIonReorderGroupElement;
53+
}
54+
55+
```
56+
57+
### ReorderEndCustomEvent
3758

3859
While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing with Ionic events emitted from this component.
3960

61+
```typescript
62+
interface ReorderEndCustomEvent extends CustomEvent {
63+
detail: ReorderEndEventDetail;
64+
target: HTMLIonReorderGroupElement;
65+
}
66+
```
67+
68+
### ItemReorderEventDetail (deprecated)
69+
70+
**_Deprecated_** — Use the `ionReorderEnd` event with `ReorderEndEventDetail` instead.
71+
72+
```typescript
73+
interface ItemReorderEventDetail {
74+
from: number;
75+
to: number;
76+
complete: (data?: boolean | any[]) => any;
77+
}
78+
```
79+
80+
### ItemReorderCustomEvent (deprecated)
81+
82+
**_Deprecated_** — Use the `ionReorderEnd` event with `ReorderEndCustomEvent` instead.
83+
4084
```typescript
4185
interface ItemReorderCustomEvent extends CustomEvent {
4286
detail: ItemReorderEventDetail;

docs/api/reorder.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import EncapsulationPill from '@components/page/api/EncapsulationPill';
2020

2121
Reorder is a component that allows an item to be dragged to change its order within a group of items. It must be used within a [reorder group](./reorder-group) to provide a visual drag and drop interface.
2222

23-
The reorder is the anchor used to drag and drop the items. Once the reorder is complete, the `ionItemReorder` event will be dispatched from the reorder group and the `complete` method needs to be called.
23+
The reorder is the anchor used to drag and drop the items. Once the reorder is complete, the `ionReorderEnd` event will be dispatched from the reorder group and the `complete` method needs to be called.
2424

2525

2626
## Basic Usage
@@ -73,6 +73,29 @@ import UpdatingData from '@site/static/usage/v8/reorder/updating-data/index.md';
7373

7474
<UpdatingData />
7575

76+
## Event Handling
77+
78+
### Using `ionReorderStart` and `ionReorderEnd`
79+
80+
The `ionReorderStart` event is emitted when the user begins a reorder gesture. This event fires when the user taps and holds an item, before any movement occurs. This is useful for preparing the UI for the reorder operation, such as hiding certain elements or updating the visual state of items. For example, icons in list items can be hidden while they are being dragged and shown again when the reorder is complete.
81+
82+
The `ionReorderEnd` event is emitted when the user completes the reorder gesture. This occurs when the user releases the item they are dragging, for example by lifting their finger on a touch screen or releasing the mouse button. The event includes the `from` and `to` indices of the item, as well as the `complete` method that should be called to finalize the reorder operation. The `from` index will always be the position of the item when the gesture started, while the `to` index will be its final position. This event will fire even if no items have changed position, in which case the `from` and `to` indices will be the same.
83+
84+
import ReorderStartEndEvents from '@site/static/usage/v8/reorder/reorder-start-end-events/index.md';
85+
86+
<ReorderStartEndEvents />
87+
88+
### Using `ionReorderMove`
89+
90+
The `ionReorderMove` event is emitted continuously during the reorder gesture as the user drags an item. The event includes the `from` and `to` indices of the item. Unlike `ionReorderEnd`, the `from` index in this event represents the last known position of the item (which updates as the item moves), while the `to` index represents its current position. If the item has not changed position since the last event, the `from` and `to` indices will be the same. This event is useful for tracking position changes during the drag operation. For example, the ranking or numbering of items can be updated in real-time as they are being dragged to maintain a logical ascending order.
91+
92+
:::warning
93+
Do not call the `complete` method during the `ionReorderMove` event as it can break the gesture.
94+
:::
95+
96+
import ReorderMoveEvent from '@site/static/usage/v8/reorder/reorder-move-event/index.md';
97+
98+
<ReorderMoveEvent />
7699

77100
## Usage with Virtual Scroll
78101

plugins/docusaurus-plugin-ionic-component-api/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ ${properties
145145
.map((prop) => {
146146
const isDeprecated = prop.deprecation !== undefined;
147147
148-
const docs = isDeprecated ? `${prop.docs}\n_Deprecated_ ${prop.deprecation}` : prop.docs;
148+
const docs = isDeprecated ? `${prop.docs}\n\n**_Deprecated_** — ${prop.deprecation}` : prop.docs;
149149
150150
return `
151151
### ${prop.name} ${isDeprecated ? '(deprecated)' : ''}
@@ -170,7 +170,15 @@ function renderEvents({ events }) {
170170
return `
171171
| Name | Description | Bubbles |
172172
| --- | --- | --- |
173-
${events.map((event) => `| \`${event.event}\` | ${formatMultiline(event.docs)} | \`${event.bubbles}\` |`).join('\n')}`;
173+
${events
174+
.map((event) => {
175+
const isDeprecated = event.deprecation !== undefined;
176+
const docs = isDeprecated ? `${event.docs}\n\n**_Deprecated_** — ${event.deprecation}` : event.docs;
177+
return `| \`${event.event}\` ${isDeprecated ? '**(deprecated)**' : ''} | ${formatMultiline(docs)} | \`${
178+
event.bubbles
179+
}\` |`;
180+
})
181+
.join('\n')}`;
174182
}
175183

176184
/**

static/demos/api/reorder/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
function toggleReorder() {
100100
const reorderGroup = document.getElementById('reorder');
101101
reorderGroup.disabled = !reorderGroup.disabled;
102-
reorderGroup.addEventListener('ionItemReorder', ({ detail }) => {
102+
reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
103103
detail.complete(true);
104104
});
105105
}

static/usage/v8/reorder/basic/angular/example_component_html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ion-list>
33
<!-- The reorder gesture is disabled by default, enable it to drag and drop items -->
44
<!-- Casting $event to $any is a temporary fix for this bug https://github.com/ionic-team/ionic-framework/issues/24245 -->
5-
<ion-reorder-group [disabled]="false" (ionItemReorder)="handleReorder($any($event))">
5+
<ion-reorder-group [disabled]="false" (ionReorderEnd)="handleReorderEnd($any($event))">
66
<ion-item>
77
<ion-label> Item 1 </ion-label>
88
<ion-reorder slot="end"></ion-reorder>

static/usage/v8/reorder/basic/angular/example_component_ts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
```ts
22
import { Component } from '@angular/core';
33
import {
4-
ItemReorderEventDetail,
54
IonItem,
65
IonLabel,
76
IonList,
87
IonReorder,
98
IonReorderGroup,
9+
ReorderEndCustomEvent,
1010
} from '@ionic/angular/standalone';
1111

1212
@Component({
@@ -16,14 +16,14 @@ import {
1616
imports: [IonItem, IonLabel, IonList, IonReorder, IonReorderGroup],
1717
})
1818
export class ExampleComponent {
19-
handleReorder(event: CustomEvent<ItemReorderEventDetail>) {
19+
handleReorderEnd(event: ReorderEndCustomEvent) {
2020
// The `from` and `to` properties contain the index of the item
2121
// when the drag started and ended, respectively
2222
console.log('Dragged from index', event.detail.from, 'to', event.detail.to);
2323

2424
// Finish the reorder and position the item in the DOM based on
2525
// where the gesture ended. This method can also be called directly
26-
// by the reorder group
26+
// by the reorder group.
2727
event.detail.complete();
2828
}
2929
}

static/usage/v8/reorder/basic/demo.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<style>
1313
ion-list {
14-
width: 100%;
14+
width: 300px;
1515
}
1616
</style>
1717
</head>
@@ -56,14 +56,14 @@
5656
<script>
5757
const reorderGroup = document.querySelector('ion-reorder-group');
5858

59-
reorderGroup.addEventListener('ionItemReorder', ({ detail }) => {
59+
reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
6060
// The `from` and `to` properties contain the index of the item
6161
// when the drag started and ended, respectively
6262
console.log('Dragged from index', detail.from, 'to', detail.to);
6363

6464
// Finish the reorder and position the item in the DOM based on
6565
// where the gesture ended. This method can also be called directly
66-
// by the reorder group
66+
// by the reorder group.
6767
detail.complete();
6868
});
6969
</script>

static/usage/v8/reorder/basic/javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
<script>
3333
const reorderGroup = document.querySelector('ion-reorder-group');
3434
35-
reorderGroup.addEventListener('ionItemReorder', ({ detail }) => {
35+
reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
3636
// The `from` and `to` properties contain the index of the item
3737
// when the drag started and ended, respectively
3838
console.log('Dragged from index', detail.from, 'to', detail.to);
3939
4040
// Finish the reorder and position the item in the DOM based on
4141
// where the gesture ended. This method can also be called directly
42-
// by the reorder group
42+
// by the reorder group.
4343
detail.complete();
4444
});
4545
</script>

static/usage/v8/reorder/basic/react.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
```tsx
22
import React from 'react';
3-
import { IonItem, IonLabel, IonList, IonReorder, IonReorderGroup, ItemReorderEventDetail } from '@ionic/react';
3+
import { IonItem, IonLabel, IonList, IonReorder, IonReorderGroup, ReorderEndCustomEvent } from '@ionic/react';
44

55
function Example() {
6-
function handleReorder(event: CustomEvent<ItemReorderEventDetail>) {
6+
function handleReorderEnd(event: ReorderEndCustomEvent) {
77
// The `from` and `to` properties contain the index of the item
88
// when the drag started and ended, respectively
99
console.log('Dragged from index', event.detail.from, 'to', event.detail.to);
1010

1111
// Finish the reorder and position the item in the DOM based on
1212
// where the gesture ended. This method can also be called directly
13-
// by the reorder group
13+
// by the reorder group.
1414
event.detail.complete();
1515
}
1616

1717
return (
1818
<IonList>
1919
{/* The reorder gesture is disabled by default, enable it to drag and drop items */}
20-
<IonReorderGroup disabled={false} onIonItemReorder={handleReorder}>
20+
<IonReorderGroup disabled={false} onIonReorderEnd={handleReorderEnd}>
2121
<IonItem>
2222
<IonLabel>Item 1</IonLabel>
2323
<IonReorder slot="end"></IonReorder>

static/usage/v8/reorder/basic/vue.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<template>
33
<ion-list>
44
<!-- The reorder gesture is disabled by default, enable it to drag and drop items -->
5-
<ion-reorder-group :disabled="false" @ionItemReorder="handleReorder($event)">
5+
<ion-reorder-group :disabled="false" @ionReorderEnd="handleReorderEnd($event)">
66
<ion-item>
77
<ion-label> Item 1 </ion-label>
88
<ion-reorder slot="end"></ion-reorder>
@@ -32,24 +32,24 @@
3232
</template>
3333

3434
<script lang="ts">
35-
import { IonItem, IonLabel, IonList, IonReorder, IonReorderGroup } from '@ionic/vue';
35+
import { IonItem, IonLabel, IonList, IonReorder, IonReorderGroup, ReorderEndCustomEvent } from '@ionic/vue';
3636
import { defineComponent } from 'vue';
3737
3838
export default defineComponent({
3939
components: { IonItem, IonLabel, IonList, IonReorder, IonReorderGroup },
4040
setup() {
41-
const handleReorder = (event: CustomEvent) => {
41+
const handleReorderEnd = (event: ReorderEndCustomEvent) => {
4242
// The `from` and `to` properties contain the index of the item
4343
// when the drag started and ended, respectively
4444
console.log('Dragged from index', event.detail.from, 'to', event.detail.to);
4545
4646
// Finish the reorder and position the item in the DOM based on
4747
// where the gesture ended. This method can also be called directly
48-
// by the reorder group
48+
// by the reorder group.
4949
event.detail.complete();
5050
};
5151
52-
return { handleReorder };
52+
return { handleReorderEnd };
5353
},
5454
});
5555
</script>

static/usage/v8/reorder/custom-icon/angular/example_component_html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ion-list>
33
<!-- The reorder gesture is disabled by default, enable it to drag and drop items -->
44
<!-- Casting $event to $any is a temporary fix for this bug https://github.com/ionic-team/ionic-framework/issues/24245 -->
5-
<ion-reorder-group [disabled]="false" (ionItemReorder)="handleReorder($any($event))">
5+
<ion-reorder-group [disabled]="false" (ionReorderEnd)="handleReorderEnd($any($event))">
66
<ion-item>
77
<ion-label> Item 1 </ion-label>
88
<ion-reorder slot="end">

static/usage/v8/reorder/custom-icon/angular/example_component_ts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
```ts
22
import { Component } from '@angular/core';
33
import {
4-
ItemReorderEventDetail,
54
IonIcon,
65
IonItem,
76
IonLabel,
87
IonList,
98
IonReorder,
109
IonReorderGroup,
10+
ReorderEndCustomEvent,
1111
} from '@ionic/angular/standalone';
1212

1313
import { addIcons } from 'ionicons';
@@ -29,14 +29,14 @@ export class ExampleComponent {
2929
addIcons({ pizza });
3030
}
3131

32-
handleReorder(event: CustomEvent<ItemReorderEventDetail>) {
32+
handleReorderEnd(event: ReorderEndCustomEvent) {
3333
// The `from` and `to` properties contain the index of the item
3434
// when the drag started and ended, respectively
3535
console.log('Dragged from index', event.detail.from, 'to', event.detail.to);
3636

3737
// Finish the reorder and position the item in the DOM based on
3838
// where the gesture ended. This method can also be called directly
39-
// by the reorder group
39+
// by the reorder group.
4040
event.detail.complete();
4141
}
4242
}

static/usage/v8/reorder/custom-icon/demo.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<style>
1313
ion-list {
14-
width: 100%;
14+
width: 300px;
1515
}
1616
</style>
1717
</head>
@@ -66,14 +66,14 @@
6666
<script>
6767
const reorderGroup = document.querySelector('ion-reorder-group');
6868

69-
reorderGroup.addEventListener('ionItemReorder', ({ detail }) => {
69+
reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
7070
// The `from` and `to` properties contain the index of the item
7171
// when the drag started and ended, respectively
7272
console.log('Dragged from index', detail.from, 'to', detail.to);
7373

7474
// Finish the reorder and position the item in the DOM based on
7575
// where the gesture ended. This method can also be called directly
76-
// by the reorder group
76+
// by the reorder group.
7777
detail.complete();
7878
});
7979
</script>

static/usage/v8/reorder/custom-icon/javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
<script>
4343
const reorderGroup = document.querySelector('ion-reorder-group');
4444
45-
reorderGroup.addEventListener('ionItemReorder', ({ detail }) => {
45+
reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
4646
// The `from` and `to` properties contain the index of the item
4747
// when the drag started and ended, respectively
4848
console.log('Dragged from index', detail.from, 'to', detail.to);
4949
5050
// Finish the reorder and position the item in the DOM based on
5151
// where the gesture ended. This method can also be called directly
52-
// by the reorder group
52+
// by the reorder group.
5353
detail.complete();
5454
});
5555
</script>

0 commit comments

Comments
 (0)