mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(overlay): expose event object in backdropClick stream (#9716)
Exposes the click event object when subscribing to the `OverlayRef.backdropClick` stream. Fixes #9713.
This commit is contained in:
committed by
tinayuangao
parent
b65268365f
commit
561194746b
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user