mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat(dialog): expose backdrop clicks (#6511)
This commit is contained in:
@@ -89,6 +89,13 @@ export class MdDialogRef<T> {
|
||||
return this._beforeClose.asObservable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an observable that emits when the overlay's backdrop has been clicked.
|
||||
*/
|
||||
backdropClick(): Observable<void> {
|
||||
return this._overlayRef.backdropClick();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the dialog's position.
|
||||
* @param position New dialog position.
|
||||
|
||||
@@ -237,6 +237,30 @@ describe('MdDialog', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should emit the backdropClick stream when clicking on the overlay backdrop', async(() => {
|
||||
const dialogRef = dialog.open(PizzaMsg, {
|
||||
viewContainerRef: testViewContainerRef
|
||||
});
|
||||
|
||||
const spy = jasmine.createSpy('backdropClick spy');
|
||||
dialogRef.backdropClick().subscribe(spy);
|
||||
|
||||
viewContainerFixture.detectChanges();
|
||||
|
||||
let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
|
||||
|
||||
backdrop.click();
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
|
||||
viewContainerFixture.detectChanges();
|
||||
|
||||
viewContainerFixture.whenStable().then(() => {
|
||||
// Additional clicks after the dialog has closed should not be emitted
|
||||
backdrop.click();
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should notify the observers if a dialog has been opened', () => {
|
||||
dialog.afterOpen.subscribe(ref => {
|
||||
expect(dialog.open(PizzaMsg, {
|
||||
|
||||
Reference in New Issue
Block a user