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

Do not render "0" when parent height and width are both 0. #61

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

stonebk
Copy link

@stonebk stonebk commented Mar 8, 2017

The following will render "0":

const Foo = Dimensions()(() => <div />);
const Bar = () => {
    return <div style={{ width: 0, height: 0 }}><Foo /></div>;
};

index.jsx Outdated
@@ -168,13 +168,14 @@ module.exports = function Dimensions ({
}
return (
<div style={wrapperStyle} ref='wrapper'>
{(containerWidth || containerHeight) &&
<ComposedComponent
{(containerWidth || containerHeight)
Copy link

Choose a reason for hiding this comment

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

This way you are not creating the ComposedComponent if the dimensions are 0. This may lead to some confusion.
You could solve the printing of '0' by casting the above statement to a boolean like this !!(containerWidth || containerHeight)

Copy link
Author

@stonebk stonebk Mar 13, 2017

Choose a reason for hiding this comment

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

ComposedComponent is already not being created. {(0 || 0) && <ComposedComponent>} becomes {0} which will render "0" as text. {(0 || 0) ? <ComposedComponent> : null} becomes {null} which will render nothing.

Copy link

Choose a reason for hiding this comment

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

That is indeed true and a derp on my part. Disregard my comments ;)

@gabegorelick
Copy link

Any plans to merge this?

@yocontra
Copy link

Yeah, this is a pretty weird bug - would be great to have this merged.

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.

6 participants