Skip to content

Commit 421b7da

Browse files
brandyscarneyadamdbradley
authored andcommitted
fix(item-sliding): don't error or allow swipes with no options
Added items with the following use cases: 1. Sliding item without options 2. Sliding item with one set of dynamic options that toggle 3. Sliding item with two options, one dynamic Removing my code will cause errors in all of the above examples. Fixes #9914
1 parent e90b630 commit 421b7da

File tree

3 files changed

+62
-21
lines changed

3 files changed

+62
-21
lines changed

src/components/item/item-sliding.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const enum ItemSideFlags {
4242
})
4343
export class ItemOptions {
4444
/**
45-
* @input {string} the side the option button should be on. Defaults to right
45+
* @input {string} the side the option button should be on. Defaults to right.
4646
* If you have multiple `ion-item-options`, a side must be provided for each.
4747
*/
4848
@Input() side: string;
@@ -103,7 +103,7 @@ export const enum SlidingState {
103103
* <button ion-button (click)="favorite(item)">Favorite</button>
104104
* <button ion-button color="danger" (click)="share(item)">Share</button>
105105
* </ion-item-options>
106-
106+
*
107107
* <ion-item-options side="right">
108108
* <button ion-button (click)="unread(item)">Unread</button>
109109
* </ion-item-options>
@@ -125,7 +125,7 @@ export const enum SlidingState {
125125
* Archive
126126
* </button>
127127
* </ion-item-options>
128-
128+
*
129129
* <ion-item-options side="left">
130130
* <button ion-button (click)="archive(item)">
131131
* <ion-icon name="archive"></ion-icon>
@@ -233,6 +233,10 @@ export class ItemSliding {
233233
@ContentChildren(ItemOptions)
234234
set _itemOptions(itemOptions: QueryList<ItemOptions>) {
235235
let sides = 0;
236+
237+
// Reset left and right options in case they were removed
238+
this._leftOptions = this._rightOptions = null;
239+
236240
for (var item of itemOptions.toArray()) {
237241
var side = item.getSides();
238242
if (side === ItemSideFlags.Left) {
@@ -293,10 +297,12 @@ export class ItemSliding {
293297
}
294298

295299
let openAmount = (this._startX - x);
300+
296301
switch (this._sides) {
297302
case ItemSideFlags.Right: openAmount = Math.max(0, openAmount); break;
298303
case ItemSideFlags.Left: openAmount = Math.min(0, openAmount); break;
299304
case ItemSideFlags.Both: break;
305+
case ItemSideFlags.None: return;
300306
default: assert(false, 'invalid ItemSideFlags value'); break;
301307
}
302308

src/components/item/test/sliding/app-module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export class E2EPage {
1414
moreText: string = 'Dynamic More';
1515
archiveText: string = 'Dynamic Archive';
1616

17+
showOptions: boolean = false;
18+
1719
constructor(private nav: NavController, private alertCtrl: AlertController, private toastCtrl: ToastController) {
1820
for (let x = 0; x < 5; x++) {
1921
this.items.push(x);
@@ -28,10 +30,11 @@ export class E2EPage {
2830
if (this.moreText.includes('Dynamic')) {
2931
this.moreText = 'Changed More';
3032
this.archiveText = 'Changed Archive';
31-
33+
this.showOptions = true;
3234
} else {
3335
this.moreText = 'Dynamic More';
3436
this.archiveText = 'Dynamic Archive';
37+
this.showOptions = false;
3538
}
3639
}
3740

src/components/item/test/sliding/main.html

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,50 @@
2020

2121
<ion-list #myList>
2222

23+
<ion-item-sliding>
24+
<ion-item>
25+
<h2>No Options</h2>
26+
<p>Should not error or swipe without options</p>
27+
</ion-item>
28+
</ion-item-sliding>
29+
30+
<ion-item-sliding #item6>
31+
<ion-item>
32+
One Line, dynamic option and text
33+
</ion-item>
34+
<ion-item-options *ngIf="showOptions">
35+
<button ion-button color="primary">
36+
<ion-icon name="more"></ion-icon>
37+
{{ moreText }}
38+
</button>
39+
<button ion-button color="secondary" (click)="archive(item6)">
40+
<ion-icon name="archive"></ion-icon>
41+
{{ archiveText }}
42+
</button>
43+
</ion-item-options>
44+
</ion-item-sliding>
45+
46+
<ion-item-sliding #item6>
47+
<ion-item>
48+
Two options, one dynamic option and text
49+
</ion-item>
50+
<ion-item-options side="left">
51+
<button ion-button icon-only color="primary">
52+
<ion-icon name="more"></ion-icon>
53+
</button>
54+
</ion-item-options>
55+
<ion-item-options side="right" *ngIf="showOptions">
56+
<button ion-button color="primary">
57+
<ion-icon name="more"></ion-icon>
58+
{{ moreText }}
59+
</button>
60+
<button ion-button color="secondary" (click)="archive(item6)">
61+
<ion-icon name="archive"></ion-icon>
62+
{{ archiveText }}
63+
</button>
64+
</ion-item-options>
65+
</ion-item-sliding>
66+
2367
<ion-item-sliding #item100>
2468
<a ion-item>
2569
<h2>HubStruck Notifications</h2>
@@ -39,7 +83,7 @@ <h2>HubStruck Notifications</h2>
3983
<button ion-button icon-only color="danger" (click)="unread(item100)">
4084
<ion-icon name="trash"></ion-icon>
4185
</button>
42-
<button ion-button icon-only (click)="unread(item100)" >
86+
<button ion-button icon-only (click)="unread(item100)">
4387
<ion-icon name="star"></ion-icon>
4488
</button>
4589
</ion-item-options>
@@ -90,7 +134,6 @@ <h2>RIGHT/LEFT side - icons</h2>
90134
</ion-item-options>
91135
</ion-item-sliding>
92136

93-
94137
<ion-item-sliding #item3>
95138
<ion-item text-wrap detail-push>
96139
<h2>RIGHT/LEFT side - icons (item-left)</h2>
@@ -146,21 +189,6 @@ <h2>RIGHT/LEFT side - icons (item-left)</h2>
146189
</ion-item-options>
147190
</ion-item-sliding>
148191

149-
<ion-item-sliding #item6>
150-
<ion-item>
151-
One Line, dynamic option
152-
</ion-item>
153-
<ion-item-options>
154-
<button ion-button color="primary">
155-
<ion-icon name="more"></ion-icon>
156-
{{ moreText }}
157-
</button>
158-
<button ion-button color="secondary" (click)="archive(item6)">
159-
<ion-icon name="archive"></ion-icon>
160-
{{ archiveText }}
161-
</button>
162-
</ion-item-options>
163-
</ion-item-sliding>
164192

165193
<ion-item-sliding #item7>
166194
<ion-item>
@@ -240,17 +268,21 @@ <h3>ng-for {{data}}</h3>
240268
img {
241269
height: 100px;
242270
}
271+
243272
#download-spinner {
244273
display: none;
245274
}
246275

247276
svg circle {
248277
stroke: white;
249278
}
279+
250280
.downloading #download-spinner {
251281
display: block;
252282
}
283+
253284
.downloading .download-hide {
254285
display: none;
255286
}
287+
256288
</style>

0 commit comments

Comments
 (0)