Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Doesn't render the badge if there's no children #78

Merged
merged 1 commit into from
Oct 15, 2015

Conversation

tleunen
Copy link
Owner

@tleunen tleunen commented Oct 15, 2015

fixes #76

tleunen added a commit that referenced this pull request Oct 15, 2015
Doesn't render the badge if there's no children
@tleunen tleunen merged commit 5f61868 into master Oct 15, 2015
@tleunen tleunen deleted the 76-badge-empty-children branch October 15, 2015 23:24
@faergeek
Copy link
Contributor

Sorry, it's not what I'm talking about. It's about text prop, not children.

The point is that we're wrapping some element in Badge and we can provide text, but according to upstream styles the element is shown only if DOM element has a data-badge attribute, so if it's empty (there's no new notifications or something like that) then it doesn't make sense to render it.

@faergeek
Copy link
Contributor

Here's a selector .mdl-badge[data-badge]:after.

@tleunen
Copy link
Owner Author

tleunen commented Oct 15, 2015

Haha ok ;) Yep, actually I figured out it make no sense if the children was null as well anyway ;)
About the text, I'm not sure.. How would you render an empty badge? (just the red circle without any content)?
I'm not saying there's no fix to be made on react-mdl. But maybe we could render an empty data-badge if text is null? Because if you don't want the badge, you could not render it in your component instead of assuming Badge will not render himself

@faergeek
Copy link
Contributor

Let's assume that we have some icon for notifications and we want to show a badge only if there's a notification (mostly like on github, but with numbers), with the current implementation we will wrap component in a badge if there's notifications or don't wrap if there's none. Not so good.

Instead I guess it's assumed by upstream that if we don't want to show badge we just don't set data-badge attribute, even empty.

I can make a PR to show the difference.

@tleunen
Copy link
Owner Author

tleunen commented Oct 15, 2015

Ok so you suggest that if text is null, Badge:render returns the children then?

@faergeek
Copy link
Contributor

Not exactly. I'll make a PR to explain better :-)

@faergeek
Copy link
Contributor

It throws now when you return null from Badge.

@faergeek
Copy link
Contributor

What if instead of checking for a single element and so on and so forth we just wrap element in span in any case? Try to wrap Textfield in Badge, for example. It's confusing.

@tleunen
Copy link
Owner Author

tleunen commented Oct 19, 2015

No need to add an extra container for that.
What do you mean when you return null from Badge?

text: PropTypes.string.isRequired
}

render() {
var { children } = this.props;

// No badge if no children
if(!React.Children.count(children)) return null;
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 talking about this line.
It seems like stateless components do not support returning null from render.
Current test suite skips it somehow.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hmm weird. Do you know if there's already a bug about that on react?
Seems weird the behavior from a stateless component is different in React and in a Shallow renderer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess may be we just don't get stateless components right?)
I didn't search for a bug.

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.

Badge empty text case
2 participants