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

Passing 0 as text to <Button /> does not render any text #2703

Closed
Foxhoundn opened this issue Jul 18, 2018 · 4 comments
Closed

Passing 0 as text to <Button /> does not render any text #2703

Foxhoundn opened this issue Jul 18, 2018 · 4 comments

Comments

@Foxhoundn
Copy link

Foxhoundn commented Jul 18, 2018

Environment

  • Package version(s): 3.0.1
  • Browser and OS versions: Latest MacOS, latest Chrome

Steps to reproduce

  1. <Button text={0} />

Actual behavior

Empty button rendered

Expected behavior

Button with 0 as text should be rendered

Possible solution

I suppose you're checking if the text prop is truthy, but 0 won't be truthy.

@giladgray
Copy link
Contributor

😂 love it

@badams
Copy link
Contributor

badams commented Jul 25, 2018

@giladgray any preference on the implementation? could attempt to convert the value to a string something like

const textValue = text != null ? String(text) : undefined;

This would support values like <Button text={false} /> (not sure if this is a good thing) or do you think we just make a special case for 0?

@giladgray
Copy link
Contributor

giladgray commented Jul 25, 2018

@badams definitely do not coerce the type, just check that it's defined. text={false} should render nothing, like any other JSX usage.

@giladgray
Copy link
Contributor

this is the line to change: https://github.com/palantir/blueprint/blob/develop/packages/core/src/components/button/abstractButton.tsx#L152.

and please add a unit test.

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

No branches or pull requests

3 participants