Skip to content

Commit

Permalink
fix(reorder): item click handlers dont fire when tapping on reorder icon
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygovier committed Aug 19, 2014
1 parent d18f0f7 commit cc18a64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions js/angular/directive/itemReorderButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
17 changes: 17 additions & 0 deletions test/unit/angular/directive/item.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit cc18a64

Please sign in to comment.