Skip to content

Commit

Permalink
fix(demo/text): render 0 as number (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilariaventurini committed Sep 26, 2020
1 parent 09ce16f commit 9f98551
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/visx-text/src/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Text extends React.Component<TextProps, TextState> {
// Only perform calculations if using features that require them (multiline, scaleToFit)
if (props.width || props.scaleToFit) {
if (needCalculate) {
const words: string[] = props.children
const words: string[] = (props.children !== null && props.children !== undefined)
? props.children.toString().split(/(?:(?!\u00A0+)\s+)/)
: [];

Expand All @@ -138,7 +138,7 @@ class Text extends React.Component<TextProps, TextState> {
}

updateWordsWithoutCalculate(props: TextProps) {
const words = props.children ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : [];
const words = (props.children !== null && props.children !== undefined) ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : [];
this.setState({ wordsByLines: [{ words }] });
}

Expand Down
10 changes: 10 additions & 0 deletions packages/visx-text/test/Text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ describe('<Text />', () => {

expect(wrapperNan.text()).not.toContain('anything');
});

it("Render text when children 0 is a number", () => {
const wrapper = mount(
<Text x={0} y={0}>
{0}
</Text>,
);

expect(wrapper.text()).toContain('0');
});
});
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5241,6 +5241,11 @@ d3-array@1, d3-array@^1.1.1, d3-array@^1.2.0:
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.4.0.tgz#87f8b9ad11088769c82b5ea846bcb1cc9393f242"
integrity sha512-KQ41bAF2BMakf/HdKT865ALd4cgND6VcIztVQZUTt0+BH3RWy6ZYnHghVXf6NFjt2ritLr8H1T8LreAAlfiNcw==

d3-array@2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.6.0.tgz#b8df0c695eab26e2b2fd4ffe2d84bd703f8d0faf"
integrity sha512-1TgzIGb6hrHKSCGccdL209Ibk41HCeyv5znFEvJfBsBGhD3qpoHt/2W2ECpyLxpG1k7aNJz0BYrmLpVs9hIGNQ==

d3-chord@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/d3-chord/-/d3-chord-1.0.6.tgz#309157e3f2db2c752f0280fedd35f2067ccbb15f"
Expand Down

0 comments on commit 9f98551

Please sign in to comment.