fix(reorder): item click handlers dont fire when tapping on reorder icon

This commit is contained in:
Perry Govier
2014-08-19 11:32:35 -05:00
parent d18f0f77cd
commit cc18a64bf4
2 changed files with 22 additions and 0 deletions

View File

@@ -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');

View File

@@ -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('<ion-item ng-click="click()"><ion-reorder-button></ion-reorder-button></ion-item>');
$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('<ion-item><ion-reorder-button ng-click="click()"></ion-reorder-button></ion-item>');
$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() {