Skip to content

Commit 2a915d1

Browse files
iterianithePunderWoman
authored andcommitted
refactor(core): Remove clickmod support from Angular. (angular#57201)
This was an old feature that mapped shift + click (et al) to "clickmod". This doesn't really make sense to add to Angular, so let's remove it. PR Close angular#57201
1 parent d73a374 commit 2a915d1

5 files changed

Lines changed: 16 additions & 13 deletions

File tree

goldens/public-api/core/primitives/event-dispatch/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class EventContractContainer implements EventContractContainerManager {
5050

5151
// @public
5252
export class EventDispatcher {
53-
constructor(dispatchDelegate: (event: Event, actionName: string) => void);
53+
constructor(dispatchDelegate: (event: Event, actionName: string) => void, clickModSupport?: boolean);
5454
dispatch(eventInfo: EventInfo): void;
5555
}
5656

packages/core/primitives/event-dispatch/src/action_resolver.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const DEFAULT_EVENT_TYPE: string = EventType.CLICK;
3232
/** Resolves actions for Events. */
3333
export class ActionResolver {
3434
private a11yClickSupport: boolean = false;
35+
private clickModSupport: boolean = true;
3536
private readonly syntheticMouseEventSupport: boolean;
3637

3738
private updateEventInfoForA11yClick?: (eventInfo: eventInfoLib.EventInfo) => void = undefined;
@@ -46,10 +47,13 @@ export class ActionResolver {
4647

4748
constructor({
4849
syntheticMouseEventSupport = false,
50+
clickModSupport = true,
4951
}: {
5052
syntheticMouseEventSupport?: boolean;
53+
clickModSupport?: boolean;
5154
} = {}) {
5255
this.syntheticMouseEventSupport = syntheticMouseEventSupport;
56+
this.clickModSupport = clickModSupport;
5357
}
5458

5559
resolveEventType(eventInfo: eventInfoLib.EventInfo) {
@@ -87,6 +91,7 @@ export class ActionResolver {
8791
// a11y click support is enabled, addEvent() will set up the appropriate key
8892
// event handler automatically.
8993
if (
94+
this.clickModSupport &&
9095
eventInfoLib.getEventType(eventInfo) === EventType.CLICK &&
9196
eventLib.isModifiedClickEvent(eventInfoLib.getEvent(eventInfo))
9297
) {

packages/core/primitives/event-dispatch/src/event_dispatcher.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ export class EventDispatcher {
5151

5252
private readonly dispatcher: Dispatcher;
5353

54-
constructor(private readonly dispatchDelegate: (event: Event, actionName: string) => void) {
55-
this.actionResolver = new ActionResolver();
54+
constructor(
55+
private readonly dispatchDelegate: (event: Event, actionName: string) => void,
56+
private readonly clickModSupport = true,
57+
) {
58+
this.actionResolver = new ActionResolver({clickModSupport});
5659
this.dispatcher = new Dispatcher(
5760
(eventInfoWrapper: EventInfoWrapper) => {
5861
this.dispatchToDelegate(eventInfoWrapper);

packages/core/src/event_delegation_utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ export const initGlobalEventDelegation = (
115115
const eventContract = (eventContractDetails.instance = new EventContract(
116116
new EventContractContainer(document.body),
117117
));
118-
const dispatcher = new EventDispatcher(invokeRegisteredListeners);
118+
const dispatcher = new EventDispatcher(invokeRegisteredListeners, /** clickModSupport */ false);
119119
registerDispatcher(eventContract, dispatcher);
120120
};

packages/core/test/event_dispatch/event_dispatch_spec.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {
10-
Component,
11-
ElementRef,
12-
Renderer2,
13-
ViewChild,
14-
inject,
15-
ɵprovideGlobalEventDelegation,
16-
} from '@angular/core';
9+
import {Component, Renderer2, inject, ɵprovideGlobalEventDelegation} from '@angular/core';
1710
import {ComponentFixture, TestBed} from '@angular/core/testing';
1811

1912
function configureTestingModule(components: unknown[]) {
@@ -217,9 +210,11 @@ describe('event dispatch', () => {
217210
const bottomEl = nativeElement.querySelector('#bottom')!;
218211
bottomEl.click();
219212
expect(onClickSpy).toHaveBeenCalledTimes(1);
213+
bottomEl.dispatchEvent(new MouseEvent('click', {bubbles: true, shiftKey: true}));
214+
expect(onClickSpy).toHaveBeenCalledTimes(2);
220215
(fixture.componentInstance as SimpleComponent).destroy();
221216
bottomEl.click();
222-
expect(onClickSpy).toHaveBeenCalledTimes(1);
217+
expect(onClickSpy).toHaveBeenCalledTimes(2);
223218
});
224219
});
225220
});

0 commit comments

Comments
 (0)