Skip to content

Access to DOM click event on Overlay backdropClicked emitter #9713

@Bradleycorn

Description

@Bradleycorn

Bug, feature request, or proposal:

Feature Request

What is the expected behavior?

When using an Overlay from the CDK and the user clicks on the backdrop return the underlying DOM click event to backdropClicked() subscribers. This is useful in some scenarios where we might need to do something like event.preventDefault();

What is the current behavior?

The backdropClicked() event emitter doesn't include the dom click event when it emits (it emits null),

https://github.com/angular/material2/blob/master/src/cdk/overlay/overlay-ref.ts#L279-L281

    // 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));

What are the steps to reproduce?

Create an Overlay, and subscribe to it's BackdropClicked() event emitter. Click on the backdrop, and see that the next callback receives null instead of the dom click event.

What is the use-case or motivation for changing an existing behavior?

It may be useful to stopPropigation() or preventDefault() when clicking on the backdrop of an overlay. But we can't do that if the DOM event for the click is not passed on to the backdropClicked() subscriber.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 5.2.2, CDK v5.1.0

Is there anything else we should know?

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions