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

[core] fix(Overlay): handle document click/focus in Shadow DOM #4218

Merged
merged 4 commits into from
Jul 15, 2020
Merged

[core] fix(Overlay): handle document click/focus in Shadow DOM #4218

merged 4 commits into from
Jul 15, 2020

Conversation

lmk123
Copy link
Contributor

@lmk123 lmk123 commented Jul 9, 2020

Fixes #4220

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

I use blueprint in Shadow DOM, and the Overlay component is closed even if I click inside it. This PR fix this problem.

I searched the place where event.target was used in the entire code base, it seems that only Overlay component used event.target in the event registered in the document.

Reviewers should focus on:

Screenshot

@palantirtech
Copy link
Member

Thanks for your interest in palantir/blueprint, @lmk123! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

any chance you could show me a code sandbox demonstrating the issue you're trying to fix? generally before submitting PRs to Blueprint I ask contributors to file an issue and fill out the issue template.

also, could you add a unit test for this behavior?

@@ -425,7 +425,7 @@ export class Overlay extends AbstractPureComponent2<IOverlayProps, IOverlayState

private handleDocumentClick = (e: MouseEvent) => {
const { canOutsideClickClose, isOpen, onClose } = this.props;
const eventTarget = e.target as HTMLElement;
const eventTarget = (e.composed ? e.composedPath()[0] : e.target) as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

is e.composedPath() always guaranteed to be non-empty? can you add some code comments to explain why we are adding this special logic here and on L446?

Copy link
Contributor Author

@lmk123 lmk123 Jul 10, 2020

Choose a reason for hiding this comment

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

is e.composedPath() always guaranteed to be non-empty?

Yes. It returns an array of EventTarget objects representing the objects on which an event listener will be invoked (from MDN), the first item is always equals to the event.target, or if this event is triggered in an open mode Shadow DOM, the first item is the actually element that trigger the event. There are some examples in MDN.

can you add some code comments to explain why we are adding this special logic here and on L446?

Done. A more detailed explanation can be found in #4220

@lmk123
Copy link
Contributor Author

lmk123 commented Jul 10, 2020

any chance you could show me a code sandbox demonstrating the issue you're trying to fix? generally before submitting PRs to Blueprint I ask contributors to file an issue and fill out the issue template.

I posted an issue just now: #4220

also, could you add a unit test for this behavior?

When I tried to add unit tests yesterday, I encountered some problems when installing windows-build-tools. I will try again later and submit unit tests.

@lmk123
Copy link
Contributor Author

lmk123 commented Jul 10, 2020

I ran into a problem when running yarn verify: #4221

@adidahiya adidahiya self-requested a review July 12, 2020 02:30
@adidahiya
Copy link
Contributor

Change looks good, can you try to add a unit test in a separate PR please?

@adidahiya adidahiya changed the title fix: Overlay component in Shadow DOM is closed even if I click inside it [core] fix(Overlay): handle document click/focus in Shadow DOM Jul 15, 2020
@adidahiya adidahiya merged commit ae0d446 into palantir:develop Jul 15, 2020
@lmk123
Copy link
Contributor Author

lmk123 commented Jul 16, 2020

can you try to add a unit test in a separate PR please?

I will do this in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overlay component in Shadow DOM is closed even if I click inside it
3 participants