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

[Overlay] Support nested overlays #2033

Merged
merged 4 commits into from
Jan 30, 2018
Merged

Conversation

tyscorp
Copy link
Contributor

@tyscorp tyscorp commented Jan 24, 2018

Fixes #2030

Checklist

Changes proposed in this pull request:

Uses Overlay.openStack to test if a document click is in a descendant overlay. Children overlays should always be after the parent's index, so I think this should work for most cases.

This PR does not handle the case of having a non-Overlay Blueprint.Portal or ReactDOM.createPortal.

@tyscorp
Copy link
Contributor Author

tyscorp commented Jan 24, 2018

[Overlay] Support nested overlays. Fixes #2030

Preview: documentation | landing | table

@adidahiya
Copy link
Contributor

looks like you need more containers 😅

image

@adidahiya
Copy link
Contributor

Are builds like this not allowed in free CircleCI accounts? That's unfortunate... we'll have to refactor the test workflow steps

Copy link
Contributor

@giladgray giladgray left a comment

Choose a reason for hiding this comment

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

would be suuuuuper cool to add a unit test for this!


const isClickInOverlay =
(this.containerElement != null && this.containerElement.contains(eventTarget)) ||
isClickInDescendantOverlay;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't || here cuz it makes the variable name incorrect (includes a check for clicks not in overlay). || in the if.

.slice(stackIndex)
.map(findDOMNode)
.filter(elem => elem && elem.contains)
.some(elem => elem.contains(eventTarget));
Copy link
Contributor

Choose a reason for hiding this comment

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

👌 sweet array manipulation

const stackIndex = openStack.indexOf(this);

const isClickInDescendantOverlay = openStack
.slice(stackIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm struggling to wrap my head around why this works... new ("descendant") Overlays are pushed to the end of the stack so we can slice off everything before this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

@giladgray
Copy link
Contributor

@tyscorp got a moment to update this PR? if not, please close it and i'll pick up this feature.

@tyscorp
Copy link
Contributor Author

tyscorp commented Jan 29, 2018

Thanks for the reminder. I updated with the requested changes. I'm not sure how to write a unit test for this.

@tyscorp
Copy link
Contributor Author

tyscorp commented Jan 29, 2018

[Overlay] Support nested overlays. Fixes #2030

Preview: documentation | landing | table

@giladgray
Copy link
Contributor

@tyscorp thanks! in the future, please do not amend/force-push commits--it destroys the links to outdated changes (try clicking on filename in one of my outdated comments above): https://github.com/palantir/blueprint/pull/2033/files/c263f3d136f5884357d65597524f386610bc1095#diff-567c0c7f15281ce63ededd202d7220f5

@giladgray
Copy link
Contributor

@tyscorp I'm going to need a test before I can accept this sort of change. make a test that asserts that a simple repro, ahem, doesn't reproduce after this change.

take the code that led you to this bug, simplify it to just use Overlays and some dummy content, exercise the events, and assert that the outer overlays don't close.

@tyscorp
Copy link
Contributor Author

tyscorp commented Jan 30, 2018

Added test

Preview: documentation | landing | table

@tyscorp
Copy link
Contributor Author

tyscorp commented Jan 30, 2018

Fixed lint

Preview: documentation | landing | table

Copy link
Contributor

@giladgray giladgray left a comment

Choose a reason for hiding this comment

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

looks good, though i'd like to see that test green 😄

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.

I ran the new unit test locally and it works. I'll push my edits to your branch


const isClickInDescendantOverlay = openStack
.slice(stackIndex)
.map(findDOMNode)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we change the visibility of Overlay#containerElement to public, then we can avoid this findDOMNode call. I would prefer that approach.

const isClickInOverlay = this.containerElement != null && this.containerElement.contains(eventTarget);
if (isOpen && this.props.canOutsideClickClose && !isClickInOverlay) {

if (isOpen && this.props.canOutsideClickClose && !isClickInOverlay && !isClickInDescendantOverlay) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since isClickInDescendantOverlay includes this overlay instance (openStack.slice(stackIndex) will include this Overlay), I think we can remove isClickInOverlay altogether.

const stackIndex = openStack.indexOf(this);

const isClickInDescendantOverlay = openStack
.slice(stackIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

yes

@tyscorp
Copy link
Contributor Author

tyscorp commented Jan 30, 2018

code style tweaks

Preview: documentation | landing | table

@adidahiya adidahiya merged commit ff76c4a into palantir:develop Jan 30, 2018
@adidahiya
Copy link
Contributor

thanks @tyscorp!

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.

3 participants