Skip to content

Commit

Permalink
[Core] Button should render text if text={0} (#2727)
Browse files Browse the repository at this point in the history
* Ensure that button renders text prop if defined

* test text is not empty string, preventing regression of 540b88b

* Also check children is valid

* Add assertion to test text prop
  • Loading branch information
badams authored and giladgray committed Jul 30, 2018
1 parent c83d6e4 commit 0eb9cc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
return [
loading && <Spinner key="loading" className={Classes.BUTTON_SPINNER} size={Icon.SIZE_LARGE} />,
<Icon key="leftIcon" icon={icon} />,
(text || children) && (
((text != null && text !== "") || (children != null && children !== "")) && (
<span key="text" className={Classes.BUTTON_TEXT}>
{text}
{children}
Expand Down
6 changes: 6 additions & 0 deletions packages/core/test/buttons/buttonTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ function buttonTestSuite(component: React.ComponentClass<any>, tagName: string)
assert.equal(wrapper.text(), "some text");
});

it("renders the button text prop when text={0}", () => {
const wrapper = button({ text: 0 }, true);
assert.equal(wrapper.text(), "0");
});

it("wraps string children in spans", () => {
// so text can be hidden when loading
const wrapper = button({}, true, "raw string", <em>not a string</em>);
Expand All @@ -46,6 +51,7 @@ function buttonTestSuite(component: React.ComponentClass<any>, tagName: string)

it('doesn\'t render a span if text=""', () => {
assert.equal(button({}, true, "").find("span").length, 0);
assert.equal(button({ text: "" }, true).find("span").length, 0);
});

it("renders a loading spinner when the loading prop is true", () => {
Expand Down

1 comment on commit 0eb9cc5

@blueprint-bot
Copy link

Choose a reason for hiding this comment

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

[Core] Button should render text if text={0} (#2727)

Preview: documentation | landing | table

Please sign in to comment.