Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(dialog): allow click events to propagate #869

Merged
merged 3 commits into from
Jul 13, 2017
Merged

fix(dialog): allow click events to propagate #869

merged 3 commits into from
Jul 13, 2017

Conversation

jonathanzong
Copy link
Contributor

@jonathanzong jonathanzong commented Jun 27, 2017

This PR fixes #794. I implemented the short fix proposed by @amsheehan in that thread and confirmed that listeners on the list items receive click events. cc @jverkoey

@amsheehan amsheehan self-assigned this Jun 29, 2017
@amsheehan
Copy link
Contributor

amsheehan commented Jun 29, 2017

Hey @jonathanzong, Thanks for the PR!

It looks like some of the tests are failing. As soon as that gets fixed up I'll review. From the output in Travis CI, it looks like there are two tests failing:

foundation.test.js:199
&
foundation.test.js:256

The first one we can remove since we're scrapping evt.stopPropagation(). The other will just have to be modified a little to accommodate the new (less greedy) event logic. If you could also fix the spelling mistake in the description of the second test it would be greatly appreciated!

on click closese the dialog and notifies cancellation should read: on click _closes_ the dialog and notifies cancellation

fwiw, if you run a quick npm test right before making a commit it will run the same suite of tests that Travis CI does. It will run all the unit tests, catch linting errors, and spit out coverage.

Thanks again!

@codecov-io
Copy link

codecov-io commented Jun 29, 2017

Codecov Report

Merging #869 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #869      +/-   ##
==========================================
+ Coverage   99.93%   99.93%   +<.01%     
==========================================
  Files          68       68              
  Lines        3270     3271       +1     
  Branches      402      403       +1     
==========================================
+ Hits         3268     3269       +1     
  Misses          2        2
Impacted Files Coverage Δ
packages/mdc-dialog/foundation.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad81639...2487a1e. Read the comment docs.

@jonathanzong
Copy link
Contributor Author

jonathanzong commented Jun 29, 2017

Upon further inspection I'm realizing that the intent of the removed test is to make sure click events don't propagate to items behind / unrelated to the dialog (see your comment here in #225). My solution is to stop propagation when the evt.currentTarget (as opposed to evt.target) reaches the dialog root. I think this is the approach that lets events bubble, but not too far.

@jonathanzong
Copy link
Contributor Author

Hi @amsheehan, I just updated the tests and the CI checks have passed, would appreciate your feedback!

@Garbee
Copy link
Contributor

Garbee commented Jul 6, 2017

My solution is to stop propagation when the evt.currentTarget (as opposed to evt.target) reaches the dialog root. I think this is the approach that lets events bubble, but not too far.

This isn't emulating the natural dialog element though. Natural HTML <dialog>'s allow for the event to propagate all the way to the document itself. The component should reflect that functionality to align with how the web works.

@lynnmercier lynnmercier requested a review from amsheehan July 6, 2017 18:22
Copy link
Contributor

@amsheehan amsheehan left a comment

Choose a reason for hiding this comment

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

This is pretty much there. Just a few changes and we should be good to merge this. Did you happen to do a quick sanity check across browsers with this code?

@@ -52,7 +52,14 @@ export default class MDCDialogFoundation extends MDCFoundation {
constructor(adapter) {
super(Object.assign(MDCDialogFoundation.defaultAdapter, adapter));
this.isOpen_ = false;
this.componentClickHandler_ = () => this.cancel(true);
this.componentClickHandler_ = (evt) => {
if (this.adapter_.eventTargetHasClass(evt.currentTarget, cssClasses.ROOT)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As Garbee mentioned, events should be allowed to propagate down to the document.

@@ -185,14 +185,17 @@ test('#cancel calls notifyCancel when shouldNotify is set to true', () => {
td.verify(mockAdapter.notifyCancel());
});

test('on dialog surface click calls evt.stopPropagation() to prevent click from propagating to background el', () => {
test('on dialog surface click calls evt.stopPropagation() to prevent click from propagating past the root', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Once the event is allowed to reach the document, this test should be removed.


td.verify(mockAdapter.removeClass(cssClasses.OPEN));
td.verify(mockAdapter.notifyCancel());
});

test('on click does not close or notify cancellation if event target is not the backdrop', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might be worth mentioning for future devs that this effectively means a click on the surface does not close the dialog

handlers.click(evt);

td.verify(mockAdapter.removeClass(cssClasses.OPEN), {times: 0});
td.verify(mockAdapter.notifyCancel(), {times: 0});
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be enough to test that the removeClass() adapter method isn't called.

@jonathanzong
Copy link
Contributor Author

Thanks @amsheehan, yes I did sanity check this on Chrome/Safari/Firefox and events do propagate.

Copy link
Contributor

@amsheehan amsheehan left a comment

Choose a reason for hiding this comment

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

LGTM. Slam that merge button!

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@yeelan0319 yeelan0319 merged commit ef7e540 into material-components:master Jul 13, 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.

mdc-dialog with list items ; how to listen for clicks properly?
6 participants