Skip to content

Commit 9049033

Browse files
committed
fix(ionList): if showDelete/showReorder true, always show buttons
Fixes #1181
1 parent 0af97e4 commit 9049033

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

js/angular/directive/itemDeleteButton.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,27 @@ var ITEM_TPL_DELETE_BUTTON =
3030
* ```
3131
*/
3232
IonicModule
33-
.directive('ionDeleteButton', [function() {
33+
.directive('ionDeleteButton', ['$animate', function($animate) {
3434
return {
3535
restrict: 'E',
36-
require: '^ionItem',
36+
require: ['^ionItem', '^ionList'],
3737
//Run before anything else, so we can move it before other directives process
3838
//its location (eg ngIf relies on the location of the directive in the dom)
3939
priority: Number.MAX_VALUE,
4040
compile: function($element, $attr) {
4141
//Add the classes we need during the compile phase, so that they stay
4242
//even if something else like ngIf removes the element and re-addss it
4343
$attr.$set('class', ($attr.class || '') + ' button icon button-icon', true);
44-
return function($scope, $element, $attr, itemCtrl) {
44+
return function($scope, $element, $attr, ctrls) {
45+
var itemCtrl = ctrls[0];
46+
var listCtrl = ctrls[1];
4547
var container = angular.element(ITEM_TPL_DELETE_BUTTON);
4648
container.append($element);
4749
itemCtrl.$element.append(container).addClass('item-left-editable');
50+
51+
if (listCtrl.showDelete()) {
52+
$animate.removeClass(container, 'ng-hide');
53+
}
4854
};
4955
}
5056
};

js/angular/directive/itemReorderButton.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ var ITEM_TPL_REORDER_BUTTON =
4646
* Parameters given: $fromIndex, $toIndex.
4747
*/
4848
IonicModule
49-
.directive('ionReorderButton', [function() {
49+
.directive('ionReorderButton', ['$animate', function($animate) {
5050
return {
5151
restrict: 'E',
52-
require: '^ionItem',
52+
require: ['^ionItem', '^ionList'],
5353
priority: Number.MAX_VALUE,
5454
compile: function($element, $attr) {
5555
$attr.$set('class', ($attr.class || '') + ' button icon button-icon', true);
5656
$element[0].setAttribute('data-prevent-scroll', true);
57-
return function($scope, $element, $attr, itemCtrl) {
57+
return function($scope, $element, $attr, ctrls) {
58+
var itemCtrl = ctrls[0];
59+
var listCtrl = ctrls[1];
5860
$scope.$onReorder = function(oldIndex, newIndex) {
5961
$scope.$eval($attr.onReorder, {
6062
$fromIndex: oldIndex,
@@ -65,6 +67,10 @@ IonicModule
6567
var container = angular.element(ITEM_TPL_REORDER_BUTTON);
6668
container.append($element);
6769
itemCtrl.$element.append(container).addClass('item-right-editable');
70+
71+
if (listCtrl.showReorder()) {
72+
$animate.removeClass(container, 'ng-hide');
73+
}
6874
};
6975
}
7076
};

test/unit/angular/directive/list.unit.js

+39-8
Original file line numberDiff line numberDiff line change
@@ -256,41 +256,72 @@ describe('ionItem directive', function() {
256256
describe('ionDeleteButton directive', function() {
257257
beforeEach(module('ionic'));
258258
it('should have delete button', inject(function($compile, $rootScope) {
259-
var setSpy = jasmine.createSpy('setDeleteButton')
259+
var setSpy = jasmine.createSpy('setDeleteButton');
260260
var el = angular.element('<ion-item><ion-delete-button></ion-delete-button></ion-item>');
261-
el.data('$ionListController', {});
261+
el.data('$ionListController', {
262+
showDelete: function() { return false; }
263+
});
262264
$compile(el)($rootScope.$new());
263265
$rootScope.$apply();
264266

265-
var deleteContainer = angular.element(el[0].querySelector('.item-left-edit.item-delete'));
267+
var deleteContainer = angular.element(el[0].querySelector('.item-left-edit.item-delete.ng-hide'));
266268
expect(deleteContainer.length).toBe(1);
267269
expect(deleteContainer.children().hasClass('button icon button-icon')).toBe(true);
268270
}));
271+
it('should unhide if delete is shown', inject(function($compile, $rootScope) {
272+
var setSpy = jasmine.createSpy('setDeleteButton');
273+
var el = angular.element('<ion-item><ion-delete-button></ion-delete-button></ion-item>');
274+
el.data('$ionListController', {
275+
showDelete: function() { return true; }
276+
});
277+
$compile(el)($rootScope.$new());
278+
$rootScope.$apply();
279+
280+
var deleteContainer = angular.element(el[0].querySelector('.item-left-edit.item-delete'));
281+
expect(deleteContainer.length).toBe(1);
282+
expect(deleteContainer.hasClass('ng-hide')).toBe(false);
283+
}));
269284
});
270285

271286
describe('ionReorderButton directive', function() {
272287
beforeEach(module('ionic'));
273288
it('should have reorder button', inject(function($compile, $rootScope) {
274-
var setSpy = jasmine.createSpy('setReorderButton')
289+
var setSpy = jasmine.createSpy('setReorderButton');
275290
var el = angular.element('<ion-item><ion-reorder-button></ion-reorder-button></ion-item>');
276-
el.data('$ionListController', {});
291+
el.data('$ionListController', {
292+
showReorder: function() { return false; }
293+
});
277294
$compile(el)($rootScope.$new());
278295
$rootScope.$apply();
279296

280-
var reorderContainer = angular.element(el[0].querySelector('.item-right-edit.item-reorder'));
297+
var reorderContainer = angular.element(el[0].querySelector('.item-right-edit.item-reorder.ng-hide'));
281298
expect(reorderContainer.length).toBe(1);
282299
expect(reorderContainer.children().hasClass('button icon button-icon')).toBe(true);
283300
expect(reorderContainer.attr('data-prevent-scroll')).toBe('true');
284301
expect(reorderContainer.children().attr('data-prevent-scroll')).toBe('true');
285302
}));
303+
it('should remove ng-hide if reorder is already active', inject(function($compile, $rootScope) {
304+
var setSpy = jasmine.createSpy('setReorderButton');
305+
var el = angular.element('<ion-item><ion-reorder-button></ion-reorder-button></ion-item>');
306+
el.data('$ionListController', {
307+
showReorder: function() { return true; }
308+
});
309+
$compile(el)($rootScope.$new());
310+
$rootScope.$apply();
311+
var reorderContainer = angular.element(el[0].querySelector('.item-right-edit.item-reorder'));
312+
expect(reorderContainer.length).toBe(1);
313+
expect(reorderContainer.hasClass('ng-hide')).toBe(false);
314+
}));
286315
});
287316

288317
describe('ionOptionButton directive', function() {
289318
beforeEach(module('ionic'));
290319
it('should have option button', inject(function($compile, $rootScope) {
291-
var setSpy = jasmine.createSpy('setOptionButton')
320+
var setSpy = jasmine.createSpy('setOptionButton');
292321
var el = angular.element('<ion-item><ion-option-button></ion-option-button></ion-item>');
293-
el.data('$ionListController', {});
322+
el.data('$ionListController', {
323+
showDelete: function() { return false; }
324+
});
294325
$compile(el)($rootScope.$new());
295326
$rootScope.$apply();
296327

0 commit comments

Comments
 (0)