diff --git a/src/stateDirectives.js b/src/stateDirectives.js index d2954f8db..039b213b2 100644 --- a/src/stateDirectives.js +++ b/src/stateDirectives.js @@ -87,7 +87,7 @@ function $StateRefDirective($state, $timeout) { element.bind("click", function(e) { var button = e.which || e.button; - if ((button === 0 || button == 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey && !element.attr('target')) { + if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) { // HACK: This is to allow ng-clicks to be processed before the transition is initiated: $timeout(function() { $state.go(ref.state, params, { relative: base }); diff --git a/test/stateDirectivesSpec.js b/test/stateDirectivesSpec.js index 77638d395..f4e10a012 100644 --- a/test/stateDirectivesSpec.js +++ b/test/stateDirectivesSpec.js @@ -118,6 +118,23 @@ describe('uiStateRef', function() { expect($stateParams).toEqual({ id: "5" }); })); + it('should transition when given a click that contains no data (fake-click)', inject(function($state, $stateParams, $document, $q, $timeout) { + expect($state.current.name).toEqual(''); + + triggerClick(el, { + metaKey: undefined, + ctrlKey: undefined, + shiftKey: undefined, + altKey: undefined, + button: undefined + }); + $timeout.flush(); + $q.flush(); + + expect($state.current.name).toEqual('contacts.item.detail'); + expect($stateParams).toEqual({ id: "5" }); + })); + it('should not transition states when ctrl-clicked', inject(function($state, $stateParams, $document, $q) { expect($state.$current.name).toEqual(''); triggerClick(el, { ctrlKey: true }); @@ -316,4 +333,4 @@ describe('uiSrefActive', function() { $q.flush(); expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('ng-scope'); })); -}); \ No newline at end of file +});