Skip to content

Commit 81676e6

Browse files
committed
fix(ionList): disable swiping of items while option buttons are shown
Addresses #1202
1 parent a845ff3 commit 81676e6

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

Diff for: js/angular/directive/list.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ function($animate, $timeout) {
134134
if (!isShown && !wasShown) { return; }
135135

136136
if (isShown) listCtrl.closeOptionButtons();
137+
listCtrl.canSwipeItems(!isShown);
137138

138139
$element.children().toggleClass('list-left-editing', isShown);
139140
toggleNgHide('.item-delete.item-left-edit', isShown);
@@ -146,7 +147,7 @@ function($animate, $timeout) {
146147
if (!isShown && !wasShown) { return; }
147148

148149
if (isShown) listCtrl.closeOptionButtons();
149-
listCtrl.showReorder(isShown);
150+
listCtrl.canSwipeItems(!isShown);
150151

151152
$element.children().toggleClass('list-right-editing', isShown);
152153
toggleNgHide('.item-reorder.item-right-edit', isShown);

Diff for: test/html/list.html

+10-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ <h1 class="title">Ionic Delete/Option Buttons</h1>
4141
-->
4242
<div class="padding">
4343
<div class="button-bar bar-outline bar-positive">
44-
<a class="button button-positive" ng-click="Modal.show()">Button 1</a>
45-
<a class="button button-positive" ng-click="Modal.show()">Button 2</a>
46-
<a class="button button-positive" ng-click="Modal.show()">Button 3</a>
44+
<a class="button-block button button-positive" ng-click="toggleCanSwipe()">Toggle Can Swipe (is {{canSwipe()}})</a>
4745
</div>
4846
</div>
4947

@@ -80,7 +78,15 @@ <h2>Item {{ item.id }}</h2>
8078
<script>
8179
angular.module('ionicApp', ['ionic'])
8280

83-
.controller('MyCtrl', function($scope) {
81+
.controller('MyCtrl', function($scope, $ionicListDelegate) {
82+
83+
$scope.toggleCanSwipe = function() {
84+
$ionicListDelegate.canSwipeItems(!$scope.canSwipe());
85+
};
86+
$scope.canSwipe = function() {
87+
return $ionicListDelegate.canSwipeItems();
88+
};
89+
8490

8591
$scope.data = {
8692
showDelete: false

Diff for: test/unit/angular/directive/list.unit.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,27 @@ describe('ionList directive', function() {
144144
});
145145

146146
it('should watch ctrl.showDelete when true', inject(function($animate) {
147-
var el = setup('', '<div class="item-delete item-left-edit ng-hide"></div><div></div>');
147+
var el = setup('', '<div class="item-delete item-left-edit ng-hide"></div><div></div><div class="item-content"></div></div>');
148148
flush();
149149

150150
spyOn(el.controller('ionList'), 'closeOptionButtons');
151151

152152
el.controller('ionList').showDelete(true);
153+
expect(el.controller('ionList').canSwipeItems()).toBe(true);
153154
el.scope().$apply();
154155

156+
expect(el.controller('ionList').canSwipeItems()).toBe(false);
155157
expect(el.controller('ionList').closeOptionButtons).toHaveBeenCalled();
156158
var deleteButtons = angular.element(el[0].querySelectorAll('.item-delete.item-left-edit'));
157159
expect(deleteButtons.length).not.toBe(0);
158160
expect(deleteButtons.hasClass('ng-hide')).toBe(false);
159161
expect(el.children().hasClass('list-left-editing')).toBe(true);
162+
var content = angular.element(el[0].querySelectorAll('.item-content'));
163+
expect(content.attr('data-tap-disabled')).toEqual('true');
160164
}));
161165

162166
it('should watch ctrl.showDelete when false from true', inject(function($animate) {
163-
var el = setup('', '<div class="item-delete item-left-edit"></div><div></div>');
167+
var el = setup('', '<div class="item-delete item-left-edit"></div><div></div><div class="item-content">');
164168
flush();
165169

166170
spyOn(el.controller('ionList'), 'closeOptionButtons');
@@ -170,27 +174,34 @@ describe('ionList directive', function() {
170174
el.controller('ionList').showDelete(false);
171175
el.scope().$apply();
172176

177+
expect(el.controller('ionList').canSwipeItems()).toBe(true);
173178
expect(el.controller('ionList').closeOptionButtons.callCount).toBe(1);
174179
var deleteButtons = angular.element(el[0].querySelectorAll('.item-delete.item-left-edit'));
175180
expect(deleteButtons.hasClass('ng-hide')).toBe(true);
176181
expect(deleteButtons.length).not.toBe(0);
177182
expect(el.children().hasClass('list-left-editing')).toBe(false);
183+
var content = angular.element(el[0].querySelectorAll('.item-content'));
184+
expect(content.attr('data-tap-disabled')).toBeFalsy();
178185
}));
179186

180187
it('should watch ctrl.showReorder when true', inject(function($animate) {
181-
var el = setup('show-reorder="shouldReorder"', '<div class="item-reorder item-right-edit ng-hide"></div><div></div>');
188+
var el = setup('show-reorder="shouldReorder"', '<div class="item-reorder item-right-edit ng-hide"></div><div class="item-content"></div><div></div>');
182189
flush();
183190

184191
spyOn(el.controller('ionList'), 'closeOptionButtons');
185192

186193
el.controller('ionList').showReorder(true);
194+
expect(el.controller('ionList').canSwipeItems()).toBe(true);
187195
el.scope().$apply();
188196

189197
expect(el.controller('ionList').closeOptionButtons).toHaveBeenCalled();
198+
expect(el.controller('ionList').canSwipeItems()).toBe(false);
190199
var reorderButtons = angular.element(el[0].querySelectorAll('.item-reorder.item-right-edit'));
191200
expect(reorderButtons.length).not.toBe(0);
192201
expect(reorderButtons.hasClass('ng-hide')).toBe(false);
193202
expect(el.children().hasClass('list-right-editing')).toBe(true);
203+
var content = angular.element(el[0].querySelectorAll('.item-content'));
204+
expect(content.attr('data-tap-disabled')).toEqual('true');
194205
}));
195206

196207
it('should watch ctrl.showReorder when false from true', inject(function($animate) {
@@ -204,11 +215,14 @@ describe('ionList directive', function() {
204215
el.controller('ionList').showReorder(false);
205216
el.scope().$apply();
206217

218+
expect(el.controller('ionList').canSwipeItems()).toBe(true);
207219
expect(el.controller('ionList').closeOptionButtons.callCount).toBe(1);
208220
var reorderButtons = angular.element(el[0].querySelectorAll('.item-reorder.item-right-edit'));
209221
expect(reorderButtons.length).not.toBe(0);
210222
expect(reorderButtons.hasClass('ng-hide')).toBe(true);
211223
expect(el.children().hasClass('list-right-editing')).toBe(false);
224+
var content = angular.element(el[0].querySelectorAll('.item-content'));
225+
expect(content.attr('data-tap-disabled')).toBeFalsy();
212226
}));
213227
});
214228

0 commit comments

Comments
 (0)