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

[Popover2] Make sure targetElement exists before trying to call its function #1857

Merged
merged 4 commits into from Dec 1, 2017

Conversation

tobilen
Copy link
Contributor

@tobilen tobilen commented Nov 30, 2017

Fixes #1856

Checklist

Changes proposed in this pull request:

Make sure targetElement exists before trying to call closest on it

Copy link
Contributor

@cmslewis cmslewis left a comment

Choose a reason for hiding this comment

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

Thanks for this! Nothing blocking, just one thing to fix before merging.

@@ -383,7 +383,7 @@ export class Popover2 extends AbstractComponent<IPopover2Props, IPopover2State>

private updateDarkParent() {
if (!this.props.inline && this.state.isOpen) {
const hasDarkParent = this.targetElement.closest(`.${Classes.DARK}`) != null;
const hasDarkParent = this.targetElement && this.targetElement.closest(`.${Classes.DARK}`) != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Codebase convention: explicit boolean expression please:

this.targetElement != null && ...

@cmslewis cmslewis changed the title Make sure targetElement exists before trying to call its function [Popover2] Make sure targetElement exists before trying to call its function Dec 1, 2017
@tobilen
Copy link
Contributor Author

tobilen commented Dec 1, 2017

Explicit null check

Preview: documentation | landing | table

@@ -383,7 +383,7 @@ export class Popover2 extends AbstractComponent<IPopover2Props, IPopover2State>

private updateDarkParent() {
if (!this.props.inline && this.state.isOpen) {
const hasDarkParent = this.targetElement && this.targetElement.closest(`.${Classes.DARK}`) != null;
const hasDarkParent = this.targetElement !== null && this.targetElement.closest(`.${Classes.DARK}`) != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you'll want to do double-equals (!=) so that both undefined and null satisfy the condition.

@tobilen
Copy link
Contributor Author

tobilen commented Dec 1, 2017

Explicit null check, take two. action!

Preview: documentation | landing | table

const hasDarkParent = this.targetElement.closest(`.${Classes.DARK}`) != null;
const hasDarkParent =
this.targetElement != null &&
typeof this.targetElement !== "undefined" &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Line 387 is sufficient without this additional typeof check.

@tobilen
Copy link
Contributor Author

tobilen commented Dec 1, 2017

Explicit null check, take three

Preview: documentation | landing | table

@adidahiya adidahiya merged commit 71c20c4 into palantir:master Dec 1, 2017
@tobilen tobilen deleted the fix-1856 branch December 1, 2017 18:22
@adidahiya adidahiya mentioned this pull request Dec 6, 2017
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.

None yet

3 participants