Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(overlay): expose event object in backdropClick stream #9716

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this ever be a TouchEvent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, AFAIK mobile browsers just fake it as a 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
2 changes: 1 addition & 1 deletion src/lib/sort/sort-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const _MatSortHeaderMixinBase = mixinDisabled(MatSortHeaderBase);
export type ArrowViewState = SortDirection | 'hint' | 'active';

/**
* States describing the arrow's animated position (animating fromState -> toState).
* States describing the arrow's animated position (animating fromState to toState).
* If the fromState is not defined, there will be no animated transition to the toState.
* @docs-private
*/
Expand Down