Skip to content

Commit

Permalink
fix(overlay): expose backdropClick mouse event in ConnectedOverlayDir…
Browse files Browse the repository at this point in the history
…ective (#9845)

Exposes the `MouseEvent` from the backdrop click in the `ConnectedOverlayDirective.backdropClick` emitter.

Relates to #9713.
  • Loading branch information
crisbeto authored and andrewseguin committed Feb 20, 2018
1 parent 73d9c8f commit 5a1e7fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/cdk/overlay/overlay-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ describe('Overlay directives', () => {
backdrop.click();
fixture.detectChanges();

expect(fixture.componentInstance.backdropClicked).toBe(true);
expect(fixture.componentInstance.backdropClickHandler)
.toHaveBeenCalledWith(jasmine.any(MouseEvent));
});

it('should emit positionChange appropriately', () => {
Expand Down Expand Up @@ -401,7 +402,7 @@ describe('Overlay directives', () => {
<ng-template cdk-connected-overlay [open]="isOpen" [width]="width" [height]="height"
[cdkConnectedOverlayOrigin]="triggerOverride || trigger"
[hasBackdrop]="hasBackdrop" backdropClass="mat-test-class"
(backdropClick)="backdropClicked=true" [offsetX]="offsetX" [offsetY]="offsetY"
(backdropClick)="backdropClickHandler($event)" [offsetX]="offsetX" [offsetY]="offsetY"
(positionChange)="positionChangeHandler($event)" (attach)="attachHandler()"
(detach)="detachHandler()" [minWidth]="minWidth" [minHeight]="minHeight"
[cdkConnectedOverlayPositions]="positionOverrides">
Expand All @@ -422,7 +423,7 @@ class ConnectedOverlayDirectiveTest {
offsetY = 0;
triggerOverride: CdkOverlayOrigin;
hasBackdrop: boolean;
backdropClicked = false;
backdropClickHandler = jasmine.createSpy('backdropClick handler');
positionChangeHandler = jasmine.createSpy('positionChangeHandler');
positionOverrides: ConnectionPositionPair[];
attachHandler = jasmine.createSpy('attachHandler').and.callFake(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/overlay/overlay-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
set _deprecatedHasBackdrop(_hasBackdrop: any) { this.hasBackdrop = _hasBackdrop; }

/** Event emitted when the backdrop is clicked. */
@Output() backdropClick = new EventEmitter<void>();
@Output() backdropClick = new EventEmitter<MouseEvent>();

/** Event emitted when the position has changed. */
@Output() positionChange = new EventEmitter<ConnectedOverlayPositionChange>();
Expand Down Expand Up @@ -413,8 +413,8 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
}

if (this.hasBackdrop) {
this._backdropSubscription = this._overlayRef.backdropClick().subscribe(() => {
this.backdropClick.emit();
this._backdropSubscription = this._overlayRef.backdropClick().subscribe(event => {
this.backdropClick.emit(event);
});
}
}
Expand Down

0 comments on commit 5a1e7fe

Please sign in to comment.