Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

fix: close drop-down regardless of stopPropagation() calls #2003

Merged

Conversation

Reico3
Copy link
Contributor

@Reico3 Reico3 commented Jun 2, 2017

Bug description

As of now, a click event-handler on the $document is responsible for closing an open drop-down.
The click-event stops bubbling when stopPropagation() is called anywhere on the DOM before the $document. This breaks the closing of the drop-down.

Proposed solution

Registering the event-listener in the capture phase instead of the bubble phase fixes this bug.

Plunkers

Failing use-case: http://plnkr.co/edit/MWOhIKdUNpoQK5OWTC5G
Fixed use-case: http://plnkr.co/edit/jC2R9QJGUrbzljr0YR1C

Additional information

I tested the examples and they're still working with my proposed solution. Tests are also succeeding, including the one i added.

Angular version used downstream: v1.5.11
angular-ui version used downstream: 0.19.4

Reico3 added 2 commits June 1, 2017 15:47
As of now, an event-handler on the `document` is responsible for closing the
drop-down. A click-event stops bubbling when `stopPropagation()` is called,
therefor it breaks the closing of the drop-down.

Registering the event-listener in capture phase fixes this bug.
@Jefiozie Jefiozie self-assigned this Jun 5, 2017
@Jefiozie Jefiozie self-requested a review June 7, 2017 13:03
@Jefiozie Jefiozie removed their assignment Jun 7, 2017
Copy link
Contributor

@Jefiozie Jefiozie left a comment

Choose a reason for hiding this comment

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

See my comments on the code.

//
// Using the capture phase avoids problems that araise when event.stopPropatagion()
// is called before the event reaches the `document`.
$window.document.addEventListener('click', onDocumentClick, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why should we not use $document.addEventListener instead of $window.document?

Copy link
Contributor Author

@Reico3 Reico3 Jun 8, 2017

Choose a reason for hiding this comment

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

In uiSelectchoicesDirective.js#L51 $window.document is used, so i wanted to be consistent.

Also it is not possible to add a native addEventListener to the angular $document, which is a jQuery window.document wrapper.

jQuery's aim is browser compability and capture phase is not supported by older IE's. Because Angular only supports IE9+ this should not be an issue.

@Reico3
Copy link
Contributor Author

Reico3 commented Jun 8, 2017

@Jefiozie i responded to your question.

@Reico3
Copy link
Contributor Author

Reico3 commented Jun 15, 2017

Thanks for your quick review and approval !

@Jefiozie Jefiozie merged commit 2b0b17b into angular-ui:master Aug 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants