Skip to content

Commit 8080adb

Browse files
yuheiychristopherthielen
authored andcommitted
fix: should not transition states when alt-clicked
In most browsers, clicking links with the Alt key has a special behavior, for example, Chrome downloads the target resource. As with other modifier keys, the router should stop the original navigation to avoid preventing the browser’s default behavior. When users click a link while holding the Alt key together, the browsers behave as follows. Windows 10: | Browser | Behavior | |:-----------|:--------------------------------------------| | Chrome 84 | Download the target resource | | Firefox 79 | Prevent navigation and therefore do nothing | | Edge 84 | Download the target resource | | IE 11 | No impact | macOS Catalina: | Browser | Behavior | |:-----------|:--------------------------------------------| | Chrome 84 | Download the target resource | | Firefox 79 | Prevent navigation and therefore do nothing | | Safari 13 | Download the target resource |
1 parent c1d9551 commit 8080adb

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/directives/stateDirectives.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function clickHook(
9595
const button = e.which || e.button,
9696
target = getDef();
9797

98-
if (!(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || el.attr('target'))) {
98+
if (!(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || el.attr('target'))) {
9999
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
100100
const transition = $timeout(function () {
101101
if (!el.attr('disabled')) {

test/stateDirectivesSpec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ describe('uiStateRef', function () {
232232
expect(obj($stateParams)).toEqual({});
233233
}));
234234

235+
it('should not transition states when alt-clicked', inject(function ($state, $stateParams, $q) {
236+
expect($state.$current.name).toEqual('top');
237+
expect(obj($stateParams)).toEqual({});
238+
239+
triggerClick(el, { altKey: true });
240+
timeoutFlush();
241+
$q.flush();
242+
243+
expect($state.current.name).toEqual('top');
244+
expect(obj($stateParams)).toEqual({});
245+
}));
246+
235247
it('should not transition states when middle-clicked', inject(function ($state, $stateParams, $q) {
236248
expect($state.$current.name).toEqual('top');
237249
expect(obj($stateParams)).toEqual({});

0 commit comments

Comments
 (0)