From cc18a64bf4ad2fc474d6d83288b8fcdcc368e02d Mon Sep 17 00:00:00 2001 From: Perry Govier Date: Tue, 19 Aug 2014 11:32:35 -0500 Subject: [PATCH] fix(reorder): item click handlers dont fire when tapping on reorder icon --- js/angular/directive/itemReorderButton.js | 5 +++++ test/unit/angular/directive/item.unit.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/js/angular/directive/itemReorderButton.js b/js/angular/directive/itemReorderButton.js index f4494915c31..66113899127 100644 --- a/js/angular/directive/itemReorderButton.js +++ b/js/angular/directive/itemReorderButton.js @@ -67,6 +67,11 @@ IonicModule }); }; + // prevent clicks from bubbling up to the item + if(!$attr['ngClick'] && !$attr['onClick'] && !$attr['onclick']){ + $element[0].onclick = function(e){e.stopPropagation(); return false;}; + } + var container = jqLite(ITEM_TPL_REORDER_BUTTON); container.append($element); itemCtrl.$element.append(container).addClass('item-right-editable'); diff --git a/test/unit/angular/directive/item.unit.js b/test/unit/angular/directive/item.unit.js index 0b4d1b88349..7179f1f829a 100644 --- a/test/unit/angular/directive/item.unit.js +++ b/test/unit/angular/directive/item.unit.js @@ -114,6 +114,23 @@ describe('ionReorderButton directive', function() { expect(reorderContainer.hasClass('visible')).toBe(true); expect(reorderContainer.hasClass('active')).toBe(true); })); + it('should allow click handlers, but not bubble up to item\'s click event', inject(function($compile, $rootScope) { + $rootScope.click = jasmine.createSpy('click');; + + var el = angular.element(''); + $compile(el)($rootScope); + $rootScope.$apply(); + var reorderContainer = angular.element(el[0].querySelector('ion-reorder-button')); + reorderContainer.triggerHandler('click'); + expect($rootScope.click).not.toHaveBeenCalled(); + + var el = angular.element(''); + $compile(el)($rootScope); + $rootScope.$apply(); + var reorderContainer = angular.element(el[0].querySelector('ion-reorder-button')); + reorderContainer.triggerHandler('click'); + expect($rootScope.click).toHaveBeenCalled(); + })); }); describe('ionOptionButton directive', function() {