Skip to content

Commit 717d3ff

Browse files
committed
fix(uiSref): support mock-clicks/events with no data
1 parent fd729ef commit 717d3ff

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/stateDirectives.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function $StateRefDirective($state, $timeout) {
8787

8888
element.bind("click", function(e) {
8989
var button = e.which || e.button;
90-
if ((button === 0 || button == 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey && !element.attr('target')) {
90+
if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {
9191
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
9292
$timeout(function() {
9393
$state.go(ref.state, params, { relative: base });

test/stateDirectivesSpec.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ describe('uiStateRef', function() {
118118
expect($stateParams).toEqual({ id: "5" });
119119
}));
120120

121+
it('should transition when given a click that contains no data (fake-click)', inject(function($state, $stateParams, $document, $q, $timeout) {
122+
expect($state.current.name).toEqual('');
123+
124+
triggerClick(el, {
125+
metaKey: undefined,
126+
ctrlKey: undefined,
127+
shiftKey: undefined,
128+
altKey: undefined,
129+
button: undefined
130+
});
131+
$timeout.flush();
132+
$q.flush();
133+
134+
expect($state.current.name).toEqual('contacts.item.detail');
135+
expect($stateParams).toEqual({ id: "5" });
136+
}));
137+
121138
it('should not transition states when ctrl-clicked', inject(function($state, $stateParams, $document, $q) {
122139
expect($state.$current.name).toEqual('');
123140
triggerClick(el, { ctrlKey: true });
@@ -316,4 +333,4 @@ describe('uiSrefActive', function() {
316333
$q.flush();
317334
expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('ng-scope');
318335
}));
319-
});
336+
});

0 commit comments

Comments
 (0)