Skip to content

Commit

Permalink
fix(overlay): expose event object in backdropClick stream (#9716)
Browse files Browse the repository at this point in the history
Exposes the click event object when subscribing to the `OverlayRef.backdropClick` stream.

Fixes #9713.
  • Loading branch information
crisbeto authored and tinayuangao committed Feb 1, 2018
1 parent b652683 commit 5611947
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cdk-experimental/dialog/dialog-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class DialogRef<T, R = any> {
}

/** Gets an observable that emits when the overlay's backdrop has been clicked. */
backdropClick(): Observable<void> {
backdropClick(): Observable<MouseEvent> {
return this._overlayRef.backdropClick();
}

Expand Down
7 changes: 4 additions & 3 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type ImmutableObject<T> = {
*/
export class OverlayRef implements PortalOutlet {
private _backdropElement: HTMLElement | null = null;
private _backdropClick: Subject<any> = new Subject();
private _backdropClick: Subject<MouseEvent> = new Subject();
private _attachments = new Subject<void>();
private _detachments = new Subject<void>();

Expand Down Expand Up @@ -181,7 +181,7 @@ export class OverlayRef implements PortalOutlet {
}

/** Gets an observable that emits when the backdrop has been clicked. */
backdropClick(): Observable<void> {
backdropClick(): Observable<MouseEvent> {
return this._backdropClick.asObservable();
}

Expand Down Expand Up @@ -278,7 +278,8 @@ export class OverlayRef implements PortalOutlet {

// Forward backdrop clicks such that the consumer of the overlay can perform whatever
// action desired when such a click occurs (usually closing the overlay).
this._backdropElement.addEventListener('click', () => this._backdropClick.next(null));
this._backdropElement.addEventListener('click',
(event: MouseEvent) => this._backdropClick.next(event));

// Add class to fade-in the backdrop after one frame.
if (typeof requestAnimationFrame !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ describe('Overlay', () => {
overlayRef.backdropClick().subscribe(backdropClickHandler);

backdrop.click();
expect(backdropClickHandler).toHaveBeenCalled();
expect(backdropClickHandler).toHaveBeenCalledWith(jasmine.any(MouseEvent));
});

it('should complete the backdrop click stream once the overlay is destroyed', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dialog/dialog-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class MatDialogRef<T, R = any> {
/**
* Gets an observable that emits when the overlay's backdrop has been clicked.
*/
backdropClick(): Observable<void> {
backdropClick(): Observable<MouseEvent> {
return this._overlayRef.backdropClick();
}

Expand Down

0 comments on commit 5611947

Please sign in to comment.